結果

問題 No.430 文字列検索
ユーザー sugarrrsugarrr
提出日時 2020-01-29 22:48:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,611 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 165,976 KB
実行使用メモリ 7,980 KB
最終ジャッジ日時 2023-10-14 07:52:28
合計ジャッジ時間 5,323 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

string s,t;
ll p1=1009;
ll po(ll a,ll p){
    if(p==0)return 1;
    a=mod(a);
    if(p%2==0)return po(mod(a*a),p/2);
    return mod(a*po(a,p-1));
}
ll bunbo(ll a){
    return po(a,i_5);
}

int main(){fastio
    cin>>s;
    ll m;cin>>m;
    ll n=s.size();
    ll a[n+1];
    a[0]=0;
    rep(i,0,n-1){
        a[i+1]=po(p1,i)*s[i];
        Add(a[i+1],a[i]);
    }
    ll ans=0;
    while(m--){
        cin>>t;
        ll b=0;
        ll ts=t.size();
        rep(i,0,ts-1){
            Add(b,po(p1,i)*t[i]);
        }
        rep(i,0,n-1){
            ll j=i+ts;
            if(j>n)continue;
            ll sum=mod(bunbo(po(p1,i))*mod(a[j]-a[i]));
            if(mod(sum-b)==0)ans++;
        }
        //cout<<ans<<" ";
    }
    cout<<ans<<endl;
    return 0;
}
0