結果

問題 No.430 文字列検索
ユーザー gigimegigime
提出日時 2016-10-02 22:58:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 944 bytes
コンパイル時間 1,211 ms
コンパイル使用メモリ 147,340 KB
実行使用メモリ 7,892 KB
最終ジャッジ日時 2023-08-15 17:23:20
合計ジャッジ時間 2,124 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 7 ms
7,892 KB
testcase_02 AC 4 ms
4,516 KB
testcase_03 AC 4 ms
4,660 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 8 ms
6,340 KB
testcase_12 AC 8 ms
6,896 KB
testcase_13 AC 8 ms
6,988 KB
testcase_14 AC 6 ms
6,044 KB
testcase_15 AC 5 ms
5,344 KB
testcase_16 AC 5 ms
5,112 KB
testcase_17 AC 5 ms
5,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0