結果

問題 No.430 文字列検索
ユーザー pyonthpyonth
提出日時 2020-08-13 05:29:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 202,068 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2024-04-18 01:09:55
合計ジャッジ時間 3,705 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 254 ms
26,624 KB
testcase_02 AC 12 ms
5,376 KB
testcase_03 AC 11 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 1 ms
5,376 KB
testcase_08 AC 244 ms
26,368 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 14 ms
5,888 KB
testcase_11 AC 62 ms
7,552 KB
testcase_12 AC 61 ms
7,680 KB
testcase_13 AC 62 ms
7,680 KB
testcase_14 AC 48 ms
5,888 KB
testcase_15 AC 38 ms
5,376 KB
testcase_16 AC 15 ms
5,376 KB
testcase_17 AC 13 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 ul = unsigned long long;
static constexpr ul base = 998244353ULL;
static constexpr ul MASK30 = (1ULL << 30) - 1;
static constexpr ul MASK31 = (1ULL << 31) - 1;
static constexpr ul MOD = (1ULL << 61) - 1;
static constexpr ul MASK61 = MOD;
ul CalcMod(ul x) {
	ul xu = x >> 61, xd = x & MASK61;
	ul res = xu + xd;
	if (res >= MOD) res -= MOD;
	return res;
}
ul Mul(ul a, ul b) {
	ul au = a >> 31, bu = b >> 31;
	ul ad = a & MASK31, bd = b & MASK31;
	ul mid = ad * bu + au * bd;
	ul midu = mid >> 30, midd = mid & MASK30;
	return CalcMod(au * bu * 2 + midu + (midd << 31) + ad * bd);
}
int main() {
	string s;
	int m;
	cin >> s >> m;
	int n = s.size();
	map<ul, int> M;
	ul K = base;
	repl(i, 1, min(11, n + 1)) {
		ul H = 0LL;
		rep(j, i) H = CalcMod(Mul(H, base) + s[j]);
		M[H]++;
		rep(j, n - i) {
			H = CalcMod(Mul(H, base) + MOD * 4 - Mul(s[j], K) + s[j + i]);
			M[H]++;
		}
		K = CalcMod(Mul(K, base));
	}
	int ans = 0;
	while (m--) {
		string t;
		cin >> t;
		ul now = 0LL;
		for (auto c : t) now = CalcMod(Mul(now, base) + c);
		ans += M[now];
	}
	cout << ans << endl;
	return 0;
}
0