結果
問題 | No.430 文字列検索 |
ユーザー | 沙耶花 |
提出日時 | 2019-08-13 08:14:02 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 882 bytes |
コンパイル時間 | 1,661 ms |
コンパイル使用メモリ | 172,640 KB |
実行使用メモリ | 4,348 KB |
最終ジャッジ日時 | 2023-10-19 15:45:58 |
合計ジャッジ時間 | 18,719 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 1,199 ms
4,348 KB |
testcase_02 | AC | 1,084 ms
4,348 KB |
testcase_03 | AC | 905 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 8 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 5 ms
4,348 KB |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | AC | 1,844 ms
4,348 KB |
testcase_16 | AC | 1,171 ms
4,348 KB |
testcase_17 | AC | 1,113 ms
4,348 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x))%modulo) #define Inf 10000000000000000 struct KMP{ string S; vector<int> A; KMP(string s){ S = s; A.resize(S.size()+1,-1); int x = -1; for(int i=0;i<S.size();i++){ while(x>=0){ if(S[i]==S[x])break; x=A[x]; } x++; if(i!=S.size()-1){ if(S[i+1] == S[x]) { A[i+1] = A[x]; continue; } } A[i+1] = x; } } //文字列[0,pos]の接尾辞と接頭辞が何文字一致しているか int get_length(int pos){ return A[pos+1]; } }; int main(){ string S; int M; cin>>S>>M; int ans = 0; for(int i=0;i<M;i++){ string c; cin>>c; KMP K((c + " " + S)); for(int j=0;j<c.size()+S.size()+1;j++){ if(K.get_length(j)==c.size())ans++; } } cout<<ans<<endl; return 0; }