結果

問題 No.430 文字列検索
ユーザー ふぃぼんふぃぼん
提出日時 2024-02-29 19:37:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,412 bytes
コンパイル時間 4,534 ms
コンパイル使用メモリ 264,636 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-29 19:37:49
合計ジャッジ時間 29,327 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 11 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 8 ms
6,676 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0