結果

問題 No.430 文字列検索
ユーザー 夜
提出日時 2021-03-02 20:09:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 329 ms / 2,000 ms
コード長 1,378 bytes
コンパイル時間 1,080 ms
コンパイル使用メモリ 99,360 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 04:51:38
合計ジャッジ時間 4,187 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 215 ms
6,944 KB
testcase_02 AC 329 ms
6,940 KB
testcase_03 AC 94 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 77 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 201 ms
6,944 KB
testcase_12 AC 206 ms
6,940 KB
testcase_13 AC 205 ms
6,940 KB
testcase_14 AC 222 ms
6,940 KB
testcase_15 AC 231 ms
6,944 KB
testcase_16 AC 190 ms
6,944 KB
testcase_17 AC 208 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int suf[200020], r[200020], r_mem[200020];
int n;
string s;
int k;
bool suf_sort(int i, int j) {
	int i1, i2, j1, j2;
	i1 = r[i];
	if (i + k > n)i2 = -1;
	else i2 = r[i + k];
	j1 = r[j];
	if (j + k > n)j2 = -1;
	else j2 = r[j + k];
	if (make_pair(i1, i2) < make_pair(j1, j2))return true;
	else return false;
}
void c_suf() {
	for (int i = 0; i <= n; i++) {
		suf[i] = i;
		if (i == n)r[i] = -1;
		else r[i] = s[i] - 'A';
	}
	for (k = 1; k <= n; k *= 2) {
		sort(suf, suf + n + 1, suf_sort);
		r_mem[suf[0]] = 0;
		for (int j = 1; j <= n; j++) {
			r_mem[suf[j]] = r_mem[suf[j - 1]];
			if (suf_sort(suf[j - 1], suf[j]))r_mem[suf[j]]++;
		}
		for (int j = 0; j <= n; j++) {
			r[j] = r_mem[j];
		}
	}
}
int suf_check(string cs) {
	int l = 0, r = n + 1;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		if (cs > s.substr(suf[mid], n - suf[mid]))l = mid;
		else r = mid;
	}
	return r;
}
int main() {
	cin >> s;
	n = s.size();
	c_suf();
	int m;
	cin >> m;
	int ans = 0;
	for (int i = 0; i < m; i++) {
		string c;
		cin >> c;
		ans += suf_check(c + '{') - suf_check(c);
	}
	cout << ans << endl;
}
0