結果
問題 |
No.430 文字列検索
|
ユーザー |
|
提出日時 | 2024-05-31 17:05:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 337 ms / 2,000 ms |
コード長 | 898 bytes |
コンパイル時間 | 4,587 ms |
コンパイル使用メモリ | 260,668 KB |
最終ジャッジ日時 | 2025-02-21 17:21:59 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; map<int,int> mp; for(int l = 1;l<11;l++){ mint hashS = 0; for(int i = 0;i<l;i++){ hashS = hashS*base + S[i]; } for(int i = 0;i+l<=S.size();i++){ mp[hashS.val()]++; if(i+l<S.size()) hashS = hashS*base + S[i+l] - coef[l]*S[i]; } } int ans = 0; for(int i = 0;i<M;i++){ mint hashT = 0; for(int j = 0;j<T[i].size();j++){ hashT = hashT*base + T[i][j]; } ans += mp[hashT.val()]; } 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(); }