結果

問題 No.2020 Sum of Common Prefix Length
ユーザー souta-1326souta-1326
提出日時 2022-07-10 22:00:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,434 bytes
コンパイル時間 4,691 ms
コンパイル使用メモリ 264,488 KB
実行使用メモリ 47,484 KB
最終ジャッジ日時 2023-09-02 06:01:03
合計ジャッジ時間 13,249 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 48 ms
4,468 KB
testcase_08 AC 49 ms
4,472 KB
testcase_09 AC 49 ms
4,468 KB
testcase_10 AC 49 ms
4,420 KB
testcase_11 AC 49 ms
4,424 KB
testcase_12 AC 49 ms
4,460 KB
testcase_13 AC 49 ms
4,620 KB
testcase_14 AC 49 ms
4,532 KB
testcase_15 AC 65 ms
10,092 KB
testcase_16 AC 65 ms
10,132 KB
testcase_17 AC 443 ms
21,512 KB
testcase_18 AC 491 ms
15,632 KB
testcase_19 AC 444 ms
16,948 KB
testcase_20 AC 277 ms
45,640 KB
testcase_21 AC 130 ms
45,976 KB
testcase_22 AC 133 ms
39,496 KB
testcase_23 AC 126 ms
38,796 KB
testcase_24 AC 120 ms
47,484 KB
testcase_25 AC 121 ms
46,248 KB
testcase_26 AC 64 ms
26,028 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 58 ms
6,196 KB
testcase_29 AC 57 ms
6,512 KB
testcase_30 AC 57 ms
6,260 KB
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define emb emplace_back
using ll = long long;
int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  //入力
  int N;cin >> N;
  vector<string> S(N);
  for(string &s:S) cin >> s;
  int node_size = 1;
  vector<vector<int>> nex(1,vector<int>(26,-1));
  vector<int> cnt({0});
  vector<int> node_itr(N);
  for(int i=0;i<N;i++){
    int now_node = 0;
    for(char c:S[i]){
      int z = c-'a';
      if(nex[now_node][z] == -1){
        nex[now_node][z] = node_size++;
        nex.emplace_back(vector<int>(26,-1));
        cnt.emplace_back(0);
      }
      now_node = nex[now_node][z];
      cnt[now_node]++;
    }
    node_itr[i] = now_node;
  }
  int Q;cin >> Q;
  for(int i=0;i<Q;i++){
    int t;cin >> t;
    if(t==1){
      int x;char c;cin >> x >> c;x--;
      int z = c-'a';
      S[x] += c;
      if(nex[node_itr[x]][z] == -1){
        nex[node_itr[x]][z] = node_size++;
        nex.emplace_back(vector<int>(26,-1));
        cnt.emplace_back(0);
      }
      node_itr[x] = nex[node_itr[x]][z];
      cnt[node_itr[x]]++;
    }
    else{
      int x;cin >> x;x--;
      int ans = 0,now_node = 0;
      for(int j=0;j<S[x].size();j++){
        now_node = nex[now_node][S[x][j]-'a'];
        if(cnt[now_node] == 1){
          ans += S[x].size()-j;break;
        }
        ans += cnt[now_node];
      }
      cout << ans << "\n";
    }
  }
}
0