結果
問題 | No.430 文字列検索 |
ユーザー | 👑 tatyam |
提出日時 | 2019-09-12 23:23:21 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 742 ms / 2,000 ms |
コード長 | 1,624 bytes |
コンパイル時間 | 3,215 ms |
コンパイル使用メモリ | 216,572 KB |
実行使用メモリ | 8,728 KB |
最終ジャッジ日時 | 2023-09-15 14:28:37 |
合計ジャッジ時間 | 11,246 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
7,572 KB |
testcase_01 | AC | 634 ms
8,680 KB |
testcase_02 | AC | 705 ms
8,532 KB |
testcase_03 | AC | 673 ms
8,456 KB |
testcase_04 | AC | 4 ms
7,812 KB |
testcase_05 | AC | 4 ms
7,684 KB |
testcase_06 | AC | 4 ms
7,848 KB |
testcase_07 | AC | 4 ms
7,676 KB |
testcase_08 | AC | 8 ms
8,496 KB |
testcase_09 | AC | 4 ms
7,572 KB |
testcase_10 | AC | 5 ms
7,832 KB |
testcase_11 | AC | 702 ms
8,496 KB |
testcase_12 | AC | 697 ms
8,464 KB |
testcase_13 | AC | 718 ms
8,456 KB |
testcase_14 | AC | 692 ms
8,728 KB |
testcase_15 | AC | 714 ms
8,636 KB |
testcase_16 | AC | 742 ms
8,568 KB |
testcase_17 | AC | 698 ms
8,624 KB |
ソースコード
#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using uint = unsigned; using ull = unsigned long long; constexpr ull mod = 0x1fffffffffffffff, base = 257; constexpr ull mask(int a) { return (1ull << a) - 1; } inline constexpr ull mul(ull a, ull b) { __uint128_t ans = __uint128_t(a) * b; ans = (ans >> 61) + (ans & mask(61)); if(ans >= mod) ans -= mod; return ans; } ull mem[50000][11]; struct RollingHash { ull hashed[50001], power[50001]; RollingHash(const string &s) { power[0] = 1; for(uint i = 0; i < s.size(); i++) { power[i + 1] = mul(power[i], base); hashed[i + 1] = mul(hashed[i], base) + s[i]; if(hashed[i + 1] >= mod) hashed[i + 1] -= mod; } } ull get(uint l, uint r) const { if(mem[l][r - l] != mod) return mem[l][r - l]; ull ret = hashed[r] + mod - mul(hashed[l], power[r - l]); if(ret >= mod) ret -= mod; return mem[l][r - l] = ret; } }; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); for(auto& i : mem) for(auto& j : i) j = mod; string s; int m; cin >> s >> m; RollingHash rh(s); int ans = 0; for(uint i = 0; i < m; i++) { string t; cin >> t; __uint128_t rh2 = 0; for(auto i : t) { rh2 *= base; rh2 = (rh2 >> 61) + (rh2 & mask(61)); rh2 += i; if(rh2 >= mod) rh2 -= mod; } for(uint i = t.size(); i < s.size() + 1; i++) ans += rh.get(i - t.size(), i) == rh2; } cout << ans << endl; }