結果
問題 | No.765 ukuku 2 |
ユーザー | Pachicobue |
提出日時 | 2018-12-13 01:33:47 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 174 ms / 3,000 ms |
コード長 | 3,225 bytes |
コンパイル時間 | 2,417 ms |
コンパイル使用メモリ | 212,612 KB |
実行使用メモリ | 31,844 KB |
最終ジャッジ日時 | 2024-09-25 03:59:15 |
合計ジャッジ時間 | 5,579 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,944 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 1 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 102 ms
25,308 KB |
testcase_31 | AC | 103 ms
24,740 KB |
testcase_32 | AC | 87 ms
21,204 KB |
testcase_33 | AC | 29 ms
31,772 KB |
testcase_34 | AC | 29 ms
31,784 KB |
testcase_35 | AC | 132 ms
31,772 KB |
testcase_36 | AC | 130 ms
31,784 KB |
testcase_37 | AC | 132 ms
31,772 KB |
testcase_38 | AC | 160 ms
31,776 KB |
testcase_39 | AC | 174 ms
31,844 KB |
testcase_40 | AC | 102 ms
25,588 KB |
testcase_41 | AC | 110 ms
27,196 KB |
testcase_42 | AC | 120 ms
28,848 KB |
testcase_43 | AC | 112 ms
26,204 KB |
testcase_44 | AC | 111 ms
26,644 KB |
testcase_45 | AC | 121 ms
29,136 KB |
testcase_46 | AC | 107 ms
26,072 KB |
testcase_47 | AC | 122 ms
30,080 KB |
testcase_48 | AC | 126 ms
29,520 KB |
testcase_49 | AC | 126 ms
29,612 KB |
ソースコード
#include <bits/stdc++.h> using ll = long long; std::mt19937 mt{std::random_device{}()}; template <typename C = std::string, ll mod1 = 1000000007LL, ll mod2 = 1000000009LL> class RollingHash { public: RollingHash(const C& s) : pow1(s.size() + 1, 1), pow2(s.size() + 1, 1), hash1(s.size() + 1, 0), hash2(s.size() + 1, 0), base1{std::uniform_int_distribution<ll>{2, mod1 - 1}(mt)}, base2{std::uniform_int_distribution<ll>{2, mod2 - 1}(mt)} { for (std::size_t i = 1; i <= s.size(); i++) { pow1[i] = (pow1[i - 1] * base1) % mod1, pow2[i] = (pow2[i - 1] * base2) % mod2, hash1[i] = (hash1[i - 1] * base1 + (ll)s[i - 1]) % mod1, hash2[i] = (hash2[i - 1] * base2 + (ll)s[i - 1]) % mod2; } } std::pair<ll, ll> getHash(const std::size_t l, const std::size_t r) const { return {(mod1 + (hash1[r] - hash1[l] * pow1[r - l]) % mod1) % mod1, (mod2 + (hash2[r] - hash2[l] * pow2[r - l]) % mod2) % mod2}; } private: std::vector<ll> pow1, pow2, hash1, hash2; const ll base1, base2; }; std::vector<int> Manacher(const std::string& S) { std::vector<int> R(S.size()); for (int i = 0, k = 1, j = 0; i < S.size(); i += k, j -= k, k = 1) { while (i >= j and i + j < S.size() and S[i - j] == S[i + j]) { ++j; } R[i] = j; while (i >= k and i + k < S.size() and k + R[i - k] < j) { R[i + k] = R[i - k], ++k; } } return R; } int main() { std::string s; std::cin >> s; const int N = s.size(); std::string S; for (const char c : s) { S.push_back(c), S.push_back('$'); } S.pop_back(); std::string R = S; std::reverse(R.begin(), R.end()); const std::string T = S + "#" + R; RollingHash<> hash(T); const auto m = Manacher(S); int max = 0; for (int i = 0; i < S.size(); i++) { if (i - m[i] == -1 and i + m[i] == S.size()) { return std::cout << N - 1 << std::endl, 0; } if (i - m[i] == -1 or i + m[i] == S.size()) { max = std::max(max, i % 2 == 1 ? m[i] / 2 * 2 : (m[i] + 1) / 2 + (m[i] - 1) / 2); continue; } { int inf = -1, sup = std::min((int)S.size() - (i + m[i]) - 1, i - m[i] + 2); while (sup - inf > 1) { const int mid = (inf + sup) / 2; const auto l = hash.getHash(2 * S.size() - i + m[i], 2 * S.size() - i + m[i] + mid); const auto r = hash.getHash(i + m[i] + 2, i + m[i] + mid + 2); (l == r ? inf : sup) = mid; } const int len = m[i] + inf; max = std::max(max, i % 2 == 1 ? len / 2 * 2 : (len + 1) / 2 + (len - 1) / 2); } { int inf = -1, sup = std::min((int)S.size() - (i + m[i]) + 1, i - m[i]); while (sup - inf > 1) { const int mid = (inf + sup) / 2; const auto l = hash.getHash(2 * S.size() - i + m[i] + 2, 2 * S.size() - i + m[i] + 2 + mid); const auto r = hash.getHash(i + m[i], i + m[i] + mid); (l == r ? inf : sup) = mid; } const int len = m[i] + inf; max = std::max(max, i % 2 == 1 ? len / 2 * 2 : (len + 1) / 2 + (len - 1) / 2); } } std::cout << max << std::endl; return 0; }