結果
問題 | No.430 文字列検索 |
ユーザー |
![]() |
提出日時 | 2020-11-17 21:16:50 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 860 bytes |
コンパイル時間 | 3,103 ms |
コンパイル使用メモリ | 197,616 KB |
最終ジャッジ日時 | 2025-01-16 01:26:14 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 WA * 4 TLE * 4 |
ソースコード
#include <iostream> #include<bits/stdc++.h> using namespace std; vector<int> table,res; int n; string s,t; vector<int> pre_kmp(string s){ vector<int> v(s.size()+1); int k; v[0]=-1; for(int i=1;i<=s.size();i++){ k=v[i-1]; while(k>=0){ if(s[k]==s[i-1])break; else k=v[k]; } v[i]=k+1; } return v; } void match(string s, string t){ int head = 0, j = 0, slen=s.size(),tlen=t.size(); while(head + j < slen){ if(t[j] == s[head + j]){ if(++j != tlen) continue; res.push_back(head); } head += j - table[j], j = max(table[j], 0); } } int main(void){ cin>>s>>n; table=pre_kmp(s); for(int i=0;i<n;i++){ cin>>t; match(s,t); } //for(auto x:res)cout<<x<<endl; cout<<res.size()<<endl; }