結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2019-11-04 16:45:56 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,889 ms / 2,000 ms |
| コード長 | 1,627 bytes |
| コンパイル時間 | 1,559 ms |
| コンパイル使用メモリ | 149,460 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-10 00:36:50 |
| 合計ジャッジ時間 | 14,286 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
int fail[2000000];
string p;
void construct(string s) {
s.push_back(' ');
REP(i, s.length() + 1) {
fail[i] = -1;
}
p = s;
for (int i = 0, j = -1; i < s.length()-1; ++i) {
while (j >= 0 && s[i] != s[j]) j = fail[j];
j++;
if (s[i + 1] == s[j]) fail[i + 1] = fail[j];
else fail[i + 1] = j;
}
}
vector<int> match(string s) {
vector<int> res;
for (int i = 0, k = 0; i < s.length(); ++i) {
while (k >= 0 && s[i] != p[k]) k = fail[k];
k++;
if (k == p.length() - 1) res.push_back(i - p.length());
}
return res;
}
int main() {
string s;
cin >> s;
int n;
cin >> n;
int ans = 0;
REP(i, n) {
string a;
cin >> a;
construct(a);
ans += match(s).size();
}
cout << ans << endl;
}
kotamanegi