結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
pyonth
|
| 提出日時 | 2020-08-13 04:32:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 594 ms / 2,000 ms |
| コード長 | 902 bytes |
| コンパイル時間 | 6,965 ms |
| コンパイル使用メモリ | 200,092 KB |
| 最終ジャッジ日時 | 2025-01-12 21:38:09 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#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;
}
pyonth