結果
| 問題 | No.430 文字列検索 | 
| コンテスト | |
| ユーザー |  gigime | 
| 提出日時 | 2016-10-02 22:58:39 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 7 ms / 2,000 ms | 
| コード長 | 944 bytes | 
| コンパイル時間 | 1,091 ms | 
| コンパイル使用メモリ | 161,004 KB | 
| 実行使用メモリ | 8,040 KB | 
| 最終ジャッジ日時 | 2024-11-10 00:02:50 | 
| 合計ジャッジ時間 | 1,713 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 14 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> void chmax(T& a,const T& b){if(a < b) a = b;}
template<typename T> void chmin(T& a,const T& b){if(b < a) a = b;}
typedef long long ll;
int N,M;
string S;
struct node{
	bool ex;
	node *next [26];
};
node root{};
void add(string t)
{
	node *p = &root;
	FOR(i,0,t.size()){
		int key = t [i] - 'A';
		if(p->next [key] == nullptr){
			p->next [key] = new node();
		}
		p = p->next [key];
	}
	p->ex = true;
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> S >> M;
	N = S.size();
	vector<string> C(M);
	FOR(i,0,M){
		cin >> C [i];
		add(C [i]);
	}
	int ans = 0;
	FOR(i,0,N){
		node *p = &root;
		for(int j = 0;j < 10 && i + j < N;j++){
			int key = S [i + j] - 'A';
			p = p->next [key];
			if(p == nullptr) break;
			ans += p->ex;
		}
	}
	cout << ans << endl;
	return 0;
}
            
            
            
        