結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
sugarrr
|
| 提出日時 | 2020-01-29 23:00:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 773 ms / 2,000 ms |
| コード長 | 1,722 bytes |
| コンパイル時間 | 2,268 ms |
| コンパイル使用メモリ | 168,780 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-10 00:40:48 |
| 合計ジャッジ時間 | 10,082 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
//#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;
}
sugarrr