結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
pazzle1230
|
| 提出日時 | 2017-09-09 12:11:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 269 ms / 2,000 ms |
| コード長 | 1,527 bytes |
| コンパイル時間 | 1,682 ms |
| コンパイル使用メモリ | 105,132 KB |
| 実行使用メモリ | 27,264 KB |
| 最終ジャッジ日時 | 2024-11-10 00:17:59 |
| 合計ジャッジ時間 | 2,267 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;
const double eps = 1e-10;
template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
struct RollingHash{
typedef unsigned long long ull;
string S;
ull B;
vector<ull> hash,p;
int len;
RollingHash(){}
RollingHash(string S,ull B=1000000007LL):S(S),B(B){init();};
void init(){
len=S.length();
hash.resize(len+1);
p.resize(len+1);
hash[0]=0;p[0]=1;
for(int i=0;i<len;i++){
hash[i+1]=hash[i]*B+S[i];
p[i+1]=p[i]*B;
}
}
//S[l,r)
ull find(int l,int r){
return hash[r]-hash[l]*p[r-l];
}
};
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
map<unsigned long long, int> mp;
string s;
int m;
cin >> s;
cin >> m;
RollingHash rh(s);
REP(i, s.size()){
for(int j = 0;j < 10 && i-j >= 0;j++){
mp[rh.find(i-j, i+1)]++;
}
}
int res = 0;
REP(i, m){
string a;
cin >> a;
RollingHash c(a);
res += mp[c.find(0, a.size())];
}
cout << res << endl;
}
pazzle1230