結果

問題 No.2020 Sum of Common Prefix Length
ユーザー souta-1326souta-1326
提出日時 2022-04-19 22:40:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,295 bytes
コンパイル時間 2,502 ms
コンパイル使用メモリ 211,460 KB
実行使用メモリ 17,692 KB
最終ジャッジ日時 2023-09-02 06:03:05
合計ジャッジ時間 16,735 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
17,692 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 1,320 ms
5,728 KB
testcase_08 AC 1,326 ms
5,868 KB
testcase_09 AC 1,326 ms
5,736 KB
testcase_10 AC 1,317 ms
5,940 KB
testcase_11 AC 830 ms
5,756 KB
testcase_12 AC 1,189 ms
5,768 KB
testcase_13 AC 1,328 ms
5,892 KB
testcase_14 AC 769 ms
5,728 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin >> N;
  vector<string> S(N);
  for(string &s:S) cin >> s;
  vector<char> node({0});
  vector<vector<int>> nex(1,vector<int>(26,-1)),cnt(1);
  for(int i=0;i<N;i++){
    int now = 0;cnt[0].emplace_back(i);
    for(char c:S[i]){
      int z = c-'a';
      if(nex[now][z] == -1){
        nex[now][z] = node.size();
        node.emplace_back(c);
        nex.emplace_back(vector<int>(26,-1));
        cnt.emplace_back(vector<int>());
      }
      now = nex[now][z];cnt[now].emplace_back(i);
    }
  }
  vector<int> ans(N),pos(N);
  for(int i=0;i<N;i++){
    int now = 0;
    for(char c:S[i]){
      int z = c-'a';
      now = nex[now][z];
      ans[i] += cnt[now].size();
    }
    pos[i] = now;
  }
  int Q;cin >> Q;
  for(int i=0;i<Q;i++){
    int t,x;cin >> t >> x;x--;
    if(t == 1){
      char c;cin >> c;
      int z = c-'a';
      if(nex[pos[x]][z] == -1){
        nex[pos[x]][z] = node.size();
        node.emplace_back(c);
        nex.emplace_back(vector<int>(26,-1));
        cnt.emplace_back(vector<int>());
      }
      pos[x] = nex[pos[x]][z];
      ans[x] += cnt[pos[x]].size();
      cnt[pos[x]].emplace_back(x);
      for(int itr:cnt[pos[x]]) ans[itr]++;
    }
    else{
      cout << ans[x] << "\n";
    }
  }

}
0