結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-10-11 12:05:09 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 499 ms / 2,000 ms |
| コード長 | 810 bytes |
| コンパイル時間 | 2,769 ms |
| コンパイル使用メモリ | 278,680 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-10-11 12:05:20 |
| 合計ジャッジ時間 | 8,474 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, j, N) for (int i = j; i < N; i++)
const int MAX_M = 50009;
const ull B = 1'000'000'007;
string S, C[MAX_M];
int M;
int countContain(string a, string b) {
int al = a.size(), bl = b.size();
if (al > bl) return 0;
ull t = 1;
rep(i, 0, al) t *= B;
ull ah = 0, bh = 0;
rep(i, 0, al) ah = ah * B + a[i];
rep(i, 0, al) bh = bh * B + b[i];
int res = 0;
rep(i, 0, bl - al + 1) {
if (ah == bh) res++;
if (i + al < bl) bh = bh * B + b[i + al] - b[i] * t;
}
return res;
}
int main() {
cin >> S >> M;
rep(i, 0, M) cin >> C[i];
int ans = 0;
rep(i, 0, M) ans += countContain(C[i], S);
cout << ans << endl;
return 0;
}