結果
問題 |
No.430 文字列検索
|
ユーザー |
![]() |
提出日時 | 2024-01-04 17:45:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 380 ms / 2,000 ms |
コード長 | 929 bytes |
コンパイル時間 | 4,446 ms |
コンパイル使用メモリ | 251,696 KB |
最終ジャッジ日時 | 2025-02-18 16:10:14 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using P = pair<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;} int yn(bool b){cout<<(b?"Yes\n":"No\n");return 0;} #include <atcoder/all> using namespace atcoder; using mint = modint998244353; int RollingHash(string s,string t){ int b=26; int sl=s.size(),tl=t.size(); if(tl > sl)return 0; unsigned long long sh=0,th=0,d=1; rep(i,tl)d*=b,sh*=b,th*=b,sh+=s[i],th+=t[i]; int res=sh==th; for(int l=0,r=tl;r<sl;l++,r++){ sh=sh*b-d*s[l]+s[r]; res+=sh==th; } return res; } int main(){ string s; cin>>s; int m;cin>>m; int ans=0; rep(i,m){ string c; cin>>c; ans+=RollingHash(s,c); } cout<<ans<<endl; }