結果
問題 | No.430 文字列検索 |
ユーザー |
|
提出日時 | 2024-05-31 17:01:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 896 bytes |
コンパイル時間 | 4,029 ms |
コンパイル使用メモリ | 255,736 KB |
最終ジャッジ日時 | 2025-02-21 17:21:42 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 6 TLE * 8 |
ソースコード
#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(); }