結果
問題 | No.765 ukuku 2 |
ユーザー | Pachicobue |
提出日時 | 2018-12-13 01:28:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,778 bytes |
コンパイル時間 | 2,643 ms |
コンパイル使用メモリ | 210,824 KB |
実行使用メモリ | 31,872 KB |
最終ジャッジ日時 | 2024-09-25 03:58:58 |
合計ジャッジ時間 | 5,702 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | WA | - |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | WA | - |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,940 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,940 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | WA | - |
testcase_23 | AC | 2 ms
6,944 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 | 2 ms
6,940 KB |
testcase_29 | AC | 1 ms
6,944 KB |
testcase_30 | AC | 103 ms
25,284 KB |
testcase_31 | AC | 97 ms
24,604 KB |
testcase_32 | AC | 88 ms
21,160 KB |
testcase_33 | AC | 29 ms
31,832 KB |
testcase_34 | AC | 29 ms
31,680 KB |
testcase_35 | WA | - |
testcase_36 | AC | 131 ms
31,812 KB |
testcase_37 | AC | 135 ms
31,872 KB |
testcase_38 | AC | 159 ms
31,784 KB |
testcase_39 | AC | 174 ms
31,668 KB |
testcase_40 | AC | 105 ms
25,728 KB |
testcase_41 | AC | 115 ms
27,432 KB |
testcase_42 | AC | 123 ms
28,988 KB |
testcase_43 | AC | 113 ms
26,272 KB |
testcase_44 | AC | 109 ms
26,468 KB |
testcase_45 | AC | 126 ms
29,216 KB |
testcase_46 | AC | 111 ms
26,028 KB |
testcase_47 | AC | 129 ms
29,960 KB |
testcase_48 | AC | 123 ms
29,608 KB |
testcase_49 | AC | 122 ms
29,508 KB |
ソースコード
#include <bits/stdc++.h> #define show(x) std::cerr << #x << " = " << (x) << std::endl 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; } template <typename T, typename A> std::ostream& operator<<(std::ostream& os, const std::vector<T, A>& v) { os << "["; for (const auto& p : v) { os << p << ","; } return (os << "]\n"); } template <typename S, typename T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) { return (os << "<" << p.first << "," << p.second << ">"); } 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(); // show(S); std::string R = S; std::reverse(R.begin(), R.end()); const std::string T = S + "#" + R; // show(T); RollingHash<> hash(T); const auto m = Manacher(S); // show(m); int max = 0; for (int i = 0; i < S.size(); i++) { // show(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 == 0 ? 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; } // show(inf); 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; } // show(inf); 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; }