結果

問題 No.430 文字列検索
ユーザー sugarrrsugarrr
提出日時 2020-01-29 23:00:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 766 ms / 2,000 ms
コード長 1,722 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 166,592 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-14 07:54:01
合計ジャッジ時間 10,116 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,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 bun[n];
    rep(i,0,n-1){
        bun[i]=bunbo(po(p1,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(a[j]-a[i])*bun[i];
            if(mod(sum-b)==0)ans++;
        }
        //cout<<ans<<" ";
    }
    cout<<ans<<endl;
    return 0;
}
0