結果
問題 | No.765 ukuku 2 |
ユーザー | Pachicobue |
提出日時 | 2018-12-13 01:29:13 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,778 bytes |
コンパイル時間 | 2,239 ms |
コンパイル使用メモリ | 211,944 KB |
実行使用メモリ | 31,836 KB |
最終ジャッジ日時 | 2024-09-25 03:59:06 |
合計ジャッジ時間 | 5,840 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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,944 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 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 | 2 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,940 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 1 ms
6,944 KB |
testcase_22 | WA | - |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,944 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 105 ms
25,200 KB |
testcase_31 | AC | 103 ms
24,540 KB |
testcase_32 | AC | 89 ms
21,252 KB |
testcase_33 | AC | 30 ms
31,788 KB |
testcase_34 | AC | 29 ms
31,748 KB |
testcase_35 | WA | - |
testcase_36 | AC | 135 ms
31,772 KB |
testcase_37 | AC | 139 ms
31,752 KB |
testcase_38 | AC | 165 ms
31,700 KB |
testcase_39 | AC | 174 ms
31,756 KB |
testcase_40 | AC | 104 ms
25,636 KB |
testcase_41 | AC | 116 ms
27,212 KB |
testcase_42 | AC | 125 ms
28,884 KB |
testcase_43 | AC | 115 ms
26,200 KB |
testcase_44 | AC | 114 ms
26,536 KB |
testcase_45 | AC | 127 ms
29,216 KB |
testcase_46 | AC | 112 ms
26,024 KB |
testcase_47 | AC | 127 ms
30,136 KB |
testcase_48 | AC | 125 ms
29,520 KB |
testcase_49 | AC | 127 ms
29,572 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; }