結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
ふぃぼん
|
| 提出日時 | 2024-02-29 19:37:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,412 bytes |
| コンパイル時間 | 4,252 ms |
| コンパイル使用メモリ | 251,592 KB |
| 最終ジャッジ日時 | 2025-02-19 22:02:39 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 TLE * 10 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P = pair<ll,ll>;
using TUP = tuple<ll,ll,ll>;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<typename T,typename U>inline bool chmax(T&a,U b){return a<b?a=b,1:0;}
template<typename T,typename U>inline bool chmin(T&a,U b){return a>b?a=b,1:0;}
template<typename T>void pvec(vector<T>&s){for(T&i:s)cout<<i<<' ';cout<<endl;}
template<typename T>void pvec(vector<vector<T>>&s){for(auto&vec:s){for(T&i:vec)cout<<i<<' ';cout<<endl;}}
int yn(bool b){cout<<(b?"Yes\n":"No\n");return 0;}
vector<int> di={1,0,-1,0},dj={0,1,0,-1};
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
ll INF=2e18;
// RollingHash sの中にtが何回出現するかO(|S|)
int roliha(string s,string t){
int b1=1009,b2=1033;
int sl=s.size(),tl=t.size();
if(tl > sl)return 0;
mint sh1=0,th1=0,d1=1;
mint sh2=0,th2=0,d2=1;
rep(i,tl)d1*=b1,sh1*=b1,th1*=b1,sh1+=s[i],th1+=t[i];
rep(i,tl)d2*=b2,sh2*=b2,th2*=b2,sh2+=s[i],th2+=t[i];
int res=(sh1==th1 && sh2==th2);
for(int l=0,r=tl;r<sl;l++,r++){
sh1=sh1*b1-d1*s[l]+s[r];
sh2=sh2*b2-d2*s[l]+s[r];
res+=(sh1==th1 && sh2==th2);
}
return res;
}
int main(){
string s;cin>>s;
int m;cin>>m;
int ans=0;
rep(i,m){
string c;cin>>c;
ans+=roliha(s,c);
}
cout<<ans<<endl;
}
ふぃぼん