結果
問題 | No.765 ukuku 2 |
ユーザー | rogi52 |
提出日時 | 2022-02-22 19:03:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,280 bytes |
コンパイル時間 | 2,318 ms |
コンパイル使用メモリ | 208,464 KB |
実行使用メモリ | 16,256 KB |
最終ジャッジ日時 | 2024-06-30 19:23:49 |
合計ジャッジ時間 | 17,918 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,948 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | WA | - |
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 | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,944 KB |
testcase_24 | AC | 2 ms
6,944 KB |
testcase_25 | WA | - |
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 | 2 ms
6,940 KB |
testcase_30 | WA | - |
testcase_31 | AC | 641 ms
12,928 KB |
testcase_32 | WA | - |
testcase_33 | AC | 285 ms
16,256 KB |
testcase_34 | AC | 284 ms
16,256 KB |
testcase_35 | AC | 950 ms
16,128 KB |
testcase_36 | WA | - |
testcase_37 | AC | 978 ms
16,256 KB |
testcase_38 | AC | 1,000 ms
16,128 KB |
testcase_39 | AC | 980 ms
16,256 KB |
testcase_40 | AC | 528 ms
13,440 KB |
testcase_41 | AC | 691 ms
14,080 KB |
testcase_42 | AC | 693 ms
14,848 KB |
testcase_43 | AC | 669 ms
13,696 KB |
testcase_44 | AC | 640 ms
13,952 KB |
testcase_45 | WA | - |
testcase_46 | AC | 685 ms
13,696 KB |
testcase_47 | AC | 689 ms
15,488 KB |
testcase_48 | WA | - |
testcase_49 | WA | - |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; struct RollingHash { static constexpr int M = 2; static constexpr long long MODS[M] = {999999937, 1000000007}; static constexpr long long BASE = 9973; vector<long long> powb[M], hash[M]; int n; RollingHash() {} RollingHash(const string& str) { init(str); } void init(const string& str) { n = str.size(); for (int k = 0; k < M; k++) { powb[k].resize(n + 1, 1); hash[k].resize(n + 1, 0); for (int i = 0; i < n; i++) { hash[k][i + 1] = (hash[k][i] * BASE + str[i]) % MODS[k]; powb[k][i + 1] = powb[k][i] * BASE % MODS[k]; } } } // get hash str[l,r) long long get(int l, int r, int k) { long long res = hash[k][r] - hash[k][l] * powb[k][r - l] % MODS[k]; if (res < 0) res += MODS[k]; return res; } }; bool match(RollingHash& rh1, int l1, int r1, RollingHash& rh2, int l2, int r2) { bool res = true; for (int k = 0; k < RollingHash::M; k++) { res &= rh1.get(l1, r1, k) == rh2.get(l2, r2, k); } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(0); string S; cin >> S; int N = S.size(); RollingHash HS(S); reverse(S.begin(), S.end()); string T = S; RollingHash HT(T); reverse(S.begin(), S.end()); auto id = [&](int i) { return N - i; }; int ans = 0; rep(i,N) { // odd 回文 .. S[i] .. : .. の最大の長さ int len = 0; { auto f = [&](int x) { if(!(0 <= i - x) || !(i + x <= N)) return false; return match(HS, i - x, i, HT, id(i + 1 + x), id(i + 1)); }; int ok = 0, ng = N; while(ng - ok > 1) { int x = (ng + ok) / 2; (f(x) ? ok : ng) = x; } len = ok; } if(len + 1 + len < N) ans = max(ans, len + 1 + len); // S[i - len] .. S[i] .. S[i + len] // erase S[i - len - 1] if (i - len - 1 >= 0) { auto f = [&](int x) { if(!(0 <= i - len - 1 - x) || !(i + len + x <= N)) return false; return match(HS, i - len - 1 - x, i - len - 1, HT, id(i + len + x), id(i + len)); }; int ok = 0, ng = N; while(ng - ok > 1) { int x = (ng + ok) / 2; (f(x) ? ok : ng) = x; } if(ok + len + 1 + len + ok < N) ans = max(ans, ok + len + 1 + len + ok); } // erase S[i + len + 1] if(i + len + 1 < N) { auto f = [&](int x) { if(!(0 <= i - len - x) || !(i + len + 1 + x <= N)) return false; return match(HS, i - len - x, i - len, HT, id(i + len + 1 + 1 + x), id(i + len + 1 + 1)); }; int ok = 0, ng = N; while(ng - ok > 1) { int x = (ng + ok) / 2; (f(x) ? ok : ng) = x; } if(ok + len + 1 + len + ok < N) ans = max(ans, ok + len + 1 + len + ok); } if(i + 1 < N) { // even 回文 .. [S[i] S[i+1]] .. : len = .. の最大の長さ if(S[i] == S[i + 1]) { int len = 0; { auto f = [&](int x) { if(!(0 <= i - x) || !(i + 1 + 1 + x <= N)) return false; return match(HS, i - x, i, HT, id(i + 1 + 1 + x), id(i + 1 + 1)); }; int ok = 0, ng = N; while(ng - ok > 1) { int x = (ng + ok) / 2; (f(x) ? ok : ng) = x; } len = ok; } if(len + 1 + 1 + len < N) ans = max(ans, len + 1 + 1 + len); // S[i - len] .. S[i] S[i + 1] .. S[i + 1 + len] // erase S[i - len - 1] if(0 <= i - len - 1) { auto f = [&](int x) { if(!(0 <= i - len - 1 - x) || !(i + 1 + len + 1 + x <= N)) return false; return match(HS, i - len - 1 - x, i - len - 1, HT, id(i + 1 + len + 1 + x), id(i + 1 + len + 1)); }; int ok = 0, ng = N; while(ng - ok > 1) { int x = (ng + ok) / 2; (f(x) ? ok : ng) = x; } if(ok + len + 1 + 1 + len + ok < N) ans = max(ans, ok + len + 1 + 1 + len + ok); } // erase S[i + 1 + len + 1] if(i + 1 + len + 1 < N) { auto f = [&](int x) { if(!(0 <= i - len - x) || !(i + 1 + len + 1 + 1 + x <= N)) return false; return match(HS, i - len - x, i - len, HT, id(i + 1 + len + 1 + 1 + x), id(i + 1 + len + 1 + 1)); }; int ok = 0, ng = N; while(ng - ok > 1) { int x = (ng + ok) / 2; (f(x) ? ok : ng) = x; } if(ok + len + 1 + 1 + len + ok < N) ans = max(ans, ok + len + 1 + 1 + len + ok); } } else { // erase S[i] => .. [S[i-1] S[i+1]] .. if(0 <= i - 1 && S[i - 1] == S[i + 1]) { auto f = [&](int x) { if(!(0 <= i - 1 - x) || !(i + 1 + 1 + x <= N)) return false; return match(HS, i - 1 - x, i - 1, HT, id(i + 1 + 1 + x), id(i + 1 + 1)); }; int ok = 0, ng = N; while(ng - ok > 1) { int x = (ng + ok) / 2; (f(x) ? ok : ng) = x; } if(ok + 1 + 1 + ok < N) ans = max(ans, ok + 1 + 1 + ok); } // erase S[i + 1] => .. [S[i] S[i + 2]] .. if(i + 2 < N && S[i] == S[i + 2]) { auto f = [&](int x) { if(!(0 <= i - x) || !(i + 2 + 1 + x <= N)) return false; return match(HS, i - x, i, HT, id(i + 2 + 1 + x), id(i + 2 + 1)); }; int ok = 0, ng = N; while(ng - ok > 1) { int x = (ng + ok) / 2; (f(x) ? ok : ng) = x; } if(ok + 1 + 1 + ok < N) ans = max(ans, ok + 1 + 1 + ok); } } } } cout << ans << endl; }