結果

問題 No.430 文字列検索
ユーザー btkbtk
提出日時 2016-10-02 23:02:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 169,072 KB
実行使用メモリ 62,596 KB
最終ジャッジ日時 2023-08-15 17:23:22
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 40 ms
61,660 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 40 ms
62,596 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 9 ms
10,896 KB
testcase_11 AC 13 ms
11,124 KB
testcase_12 AC 13 ms
11,164 KB
testcase_13 AC 14 ms
10,852 KB
testcase_14 AC 12 ms
11,180 KB
testcase_15 AC 9 ms
8,284 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
 
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}init;
typedef long long LL;
struct node{
    LL cnt;
    int nxt[26];
    node(){
        cnt=0;
        for(int i=0;i<26;i++)nxt[i]=-1;
    }
};

int main(){
    int N,M;
    string S;cin>>S>>M;
    N=S.size();
    vector<node> trie;trie.push_back(node());
    for(int i=0;i<N;i++){
        int now=0;
        for(int j=0;j<10&&i+j<N;j++){
            int c=S[i+j]-'A';
            if(trie[now].nxt[c]==-1){
                trie.push_back(node());
                trie[now].nxt[c]=trie.size()-1;
            }
            now=trie[now].nxt[c];
            trie[now].cnt++;
        }
    }
    LL res=0;
    for(int i=0;i<M;i++){
        string C;cin>>C;
        int k=C.size();
        int now=0;
        for(int j=0;j<k;j++){
            int c=C[j]-'A';
            if(trie[now].nxt[c]==-1)break;
            now=trie[now].nxt[c];
            if(j==k-1){
                res+=trie[now].cnt;
                // cout<<trie[now].cnt<<endl;
            }
        }
    }
    cout<<res<<endl;

    return 0;
}
0