結果

問題 No.430 文字列検索
ユーザー ふぃぼんふぃぼん
提出日時 2024-01-04 17:45:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 489 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 4,623 ms
コンパイル使用メモリ 263,228 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-04 17:46:06
合計ジャッジ時間 10,497 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 486 ms
6,676 KB
testcase_02 AC 465 ms
6,676 KB
testcase_03 AC 489 ms
6,676 KB
testcase_04 AC 1 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 4 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 468 ms
6,676 KB
testcase_12 AC 474 ms
6,676 KB
testcase_13 AC 482 ms
6,676 KB
testcase_14 AC 460 ms
6,676 KB
testcase_15 AC 486 ms
6,676 KB
testcase_16 AC 459 ms
6,676 KB
testcase_17 AC 465 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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