結果
問題 |
No.430 文字列検索
|
ユーザー |
![]() |
提出日時 | 2016-10-28 19:33:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 481 ms / 2,000 ms |
コード長 | 813 bytes |
コンパイル時間 | 1,327 ms |
コンパイル使用メモリ | 159,440 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-10 00:12:11 |
合計ジャッジ時間 | 6,669 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = unsigned long long; using P = std::pair<int, int>; const int INF = 1e8; const ll B = 100000007; int cnt(string b, string a) { int res = 0; int al = a.size(); int bl = b.size(); ll t = 1; for(int i = 0; i < al; i++) t *= B; ll ah = 0, bh = 0; for(int i = 0; i < al; i++) ah = ah * B + a[i]; for(int i = 0; i < al; i++) bh = bh * B + b[i]; for(int i = 0; i + al <= bl; i++) { if(ah == bh) res++; if(i + al < bl) bh = bh * B + b[i+al] - b[i] * t; } return res; } int main() { ios::sync_with_stdio(false); string S, C; int M; int ans = 0; cin >> S >> M; for(int i = 0; i < M; i++) { cin >> C; ans += cnt(S, C); } cout << ans << endl; }