結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
rokahikou1
|
| 提出日時 | 2019-09-09 14:15:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 317 ms / 2,000 ms |
| コード長 | 1,591 bytes |
| コンパイル時間 | 817 ms |
| コンパイル使用メモリ | 93,448 KB |
| 実行使用メモリ | 27,904 KB |
| 最終ジャッジ日時 | 2024-11-10 00:30:40 |
| 合計ジャッジ時間 | 2,499 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;
const int MAX = 500000,MS=2;
const ll mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash{
int n;
vector<ll> hs[MS],pw[MS];
rolling_hash(){};
rolling_hash(const string &s){
n=s.size();
for(int i=0;i<MS;i++){
hs[i].assign(n+1,0);
pw[i].assign(n+1,0);
hs[i][0]=0;
pw[i][0]=1;
for(int j=0;j<n;j++){
pw[i][j+1] = pw[i][j]*base%mod[i];
hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
}
}
}
ll get_hash(int l,int r,int i){
return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i];
}
};
int main(){
string S;
cin >> S;
int N = S.size();
rolling_hash rh(S);
map<pair<ll,ll>,ll> m[11];
for(int i=0;i<N;i++){
for(int j=0;j<10;j++){
if(i+j>=N)break;
m[j+1][make_pair(rh.get_hash(i,i+j+1,0),rh.get_hash(i,i+j+1,1))]++;
}
}
int M;
cin >> M;
ll res = 0;
rep(i,M){
string C;
cin >> C;
rolling_hash cur(C);
res+=m[C.size()][make_pair(cur.get_hash(0,C.size(),0),cur.get_hash(0,C.size(),1))];
}
cout << res << endl;
return 0;
}
rokahikou1