結果

問題 No.430 文字列検索
ユーザー pyonthpyonth
提出日時 2020-08-13 04:32:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 902 bytes
コンパイル時間 2,268 ms
コンパイル使用メモリ 202,788 KB
実行使用メモリ 32,000 KB
最終ジャッジ日時 2024-04-18 01:07:56
合計ジャッジ時間 4,268 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 325 ms
32,000 KB
testcase_02 AC 10 ms
5,376 KB
testcase_03 AC 10 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 379 ms
31,616 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 15 ms
6,400 KB
testcase_11 AC 69 ms
8,192 KB
testcase_12 AC 67 ms
8,192 KB
testcase_13 AC 67 ms
8,320 KB
testcase_14 AC 51 ms
6,400 KB
testcase_15 AC 40 ms
5,376 KB
testcase_16 AC 13 ms
5,376 KB
testcase_17 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
using u64 = std::uint_fast64_t;
using size_type = std::uint_fast32_t;
static constexpr __int128_t o = 0;
static constexpr u64 MOD = (1uL << 61) - 1;
static constexpr u64 base = 20200213;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	string s;
	int m;
	cin >> s >> m;
	int n = s.size();
	map<__int128_t, int> M;
	__int128_t K = base;
	repl(i, 1, min(11, n + 1)) {
		__int128_t H = o;
		rep(j, i) H = (H * base + s[j]) % MOD;
		M[H]++;
		rep(j, n - i) {
			H = (H * base - s[j] * K + s[j + i] + MOD) % MOD;
			M[H]++;
		}
		K = K * base % MOD;
	}
	int ans = 0;
	while (m--) {
		string t;
		cin >> t;
		__int128_t now = o;
		for (auto c : t) now = (now * base + c) % MOD;
		ans += M[now];
	}
	cout << ans << endl;
	return 0;
}
0