結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
furuya1223
|
| 提出日時 | 2017-08-25 12:44:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,360 bytes |
| コンパイル時間 | 1,646 ms |
| コンパイル使用メモリ | 171,628 KB |
| 実行使用メモリ | 13,632 KB |
| 最終ジャッジ日時 | 2024-11-10 00:17:56 |
| 合計ジャッジ時間 | 5,040 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | AC * 1 TLE * 1 -- * 12 |
ソースコード
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
/*
// シンプルな構文解析用
typedef string::const_iterator State;
class ParseError {};
//*/
struct Edge {
int from, to, cost;
bool operator<(Edge e) {
return cost < e.cost;
}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
vector<int> makeTableKMP(const string &str){
vector<int> border(str.size() + 1);
border[0] = -1;
int j = -1;
for (int i = 0; i < str.size(); i++) {
while (j >= 0 && str[i] != str[j]) j = border[j];
j++;
if (i < str.size() - 1 && str[i+1] == str[j]) border[i+1] = border[j];
else border[i+1] = j;
}
return border;
}
vector<int> searchKMP(const string& str, const string& word) {
vector<int> table = makeTableKMP(word), ret;
int m = 0, i = 0, n = str.size();
while (m + i < n) {
if (word[i] == str[m + i]) {
if (++i == (int)(word.size())) {
ret.push_back(m);
m = m + i - table[i];
i = table[i];
}
} else {
m = m + i - table[i];
if (i > 0) i = table[i];
}
}
return ret;
}
int main(void) {
string S;
int M;
cin >> S >> M;
ll ans = 0;
rep(i, M){
string word;
cin >> word;
ans += searchKMP(S, word).size();
}
cout << ans << endl;
return 0;
}
furuya1223