結果

問題 No.430 文字列検索
ユーザー ふぃぼんふぃぼん
提出日時 2024-02-29 19:45:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,994 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 4,247 ms
コンパイル使用メモリ 264,076 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-02-29 19:45:42
合計ジャッジ時間 25,090 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1,994 ms
6,548 KB
testcase_02 AC 1,963 ms
6,548 KB
testcase_03 AC 1,987 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 1 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 9 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 6 ms
6,548 KB
testcase_11 AC 1,991 ms
6,548 KB
testcase_12 AC 1,964 ms
6,548 KB
testcase_13 AC 1,988 ms
6,548 KB
testcase_14 AC 1,967 ms
6,548 KB
testcase_15 AC 1,966 ms
6,548 KB
testcase_16 AC 1,965 ms
6,548 KB
testcase_17 AC 1,970 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

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;
    rep(i,tl)d1*=b1,sh1*=b1,th1*=b1,sh1+=s[i],th1+=t[i];
    int res=(sh1==th1);
    for(int l=0,r=tl;r<sl;l++,r++){
        sh1=sh1*b1-d1*s[l]+s[r];
        res+=(sh1==th1);
    }
    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