結果
| 問題 | No.430 文字列検索 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-31 17:01:18 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 1,650 ms / 2,000 ms |
| コード長 | 896 bytes |
| 記録 | |
| コンパイル時間 | 2,914 ms |
| コンパイル使用メモリ | 278,620 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-07-04 19:35:25 |
| 合計ジャッジ時間 | 20,399 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
string S;
using mint = modint998244353;
int M;
vector<string> T;
void solve(){
ll base = 314;
vector<mint> coef(S.size() );
coef[0] = 1;
for(int i = 1;i<S.size();i++) coef[i] = coef[i-1] * base;
int ans = 0;
for(int i = 0;i<M;i++){
if(S.size() < T[i].size()) continue;
mint hashT = 0;
mint hashS = 0;
for(int j = 0;j<T[i].size();j++){
hashT = hashT*base + T[i][j];
hashS = hashS*base + S[j];
}
if(hashT == hashS) ans++;
for(int j = 0;j<S.size()-T[i].size();j++){
hashS = hashS * base + S[j+T[i].size()];
hashS -= coef[T[i].size()] * S[j];
if(hashT == hashS) ans++;
}
}
cout<<ans<<endl;
}
signed main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> S >> M;
T.resize(M);
for(int i = 0; i < M; ++i) cin >> T[i];
solve();
}