結果

問題 No.430 文字列検索
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-02-23 03:47:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,213 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 181,896 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 03:29:02
合計ジャッジ時間 5,688 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)




const int NUMC = 26;
struct Trie {
	vector<vector<int>> V;
	vector<int> C;
	void create(vector<string> S) {
		V.clear();
		V.push_back(vector<int>(NUMC + 1));
		C.push_back(0);
		sort(S.begin(), S.end());
		for (string s : S) {
			int cur = 0;
			for (char _c : s) {
				int c = _c - 'A';
				if (V[cur][c + 1] == 0) {
					V.push_back(vector<int>(NUMC + 1));
					V[cur][c + 1] = V.size() - 1;
					C.push_back(0);
				}
				cur = V[cur][c + 1];
			}
			C[cur]++;
		}
	}
	int next(int cu, char c) {
		assert(cu < V.size());
		return V[cu][c - 'A' + 1];
	}
};
//-----------------------------------------------------------------
string S;
int M;
vector<string> C;
Trie trie;
int dp[50101][1010];
//-----------------------------------------------------------------
int main() {
	cin >> S >> M;
	rep(i, 0, M) {
		string s;
		cin >> s;
		C.push_back(s);
	}

	trie.create(C);

	int ans = 0;
	int N = S.length();
	int NN = trie.V.size();

	rep(i, 0, N) {
		dp[i][0] = 1;
		rep(j, 0, NN) if(0 < dp[i][j]) dp[i + 1][trie.next(j, S[i])] += dp[i][j];
		rep(j, 0, NN) if (0 < trie.C[j]) ans += dp[i + 1][j];
	}

	cout << ans << endl;
}
0