結果
問題 | No.765 ukuku 2 |
ユーザー | mkawa2 |
提出日時 | 2022-02-08 18:47:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,284 ms / 3,000 ms |
コード長 | 2,342 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 82,436 KB |
実行使用メモリ | 97,620 KB |
最終ジャッジ日時 | 2024-06-23 14:19:56 |
合計ジャッジ時間 | 35,676 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
55,952 KB |
testcase_01 | AC | 41 ms
56,604 KB |
testcase_02 | AC | 41 ms
55,268 KB |
testcase_03 | AC | 42 ms
55,592 KB |
testcase_04 | AC | 43 ms
55,192 KB |
testcase_05 | AC | 41 ms
54,916 KB |
testcase_06 | AC | 41 ms
55,036 KB |
testcase_07 | AC | 43 ms
55,868 KB |
testcase_08 | AC | 43 ms
54,256 KB |
testcase_09 | AC | 44 ms
55,548 KB |
testcase_10 | AC | 42 ms
54,928 KB |
testcase_11 | AC | 41 ms
55,892 KB |
testcase_12 | AC | 41 ms
54,316 KB |
testcase_13 | AC | 41 ms
54,568 KB |
testcase_14 | AC | 41 ms
56,060 KB |
testcase_15 | AC | 40 ms
55,388 KB |
testcase_16 | AC | 41 ms
54,388 KB |
testcase_17 | AC | 42 ms
54,844 KB |
testcase_18 | AC | 41 ms
55,484 KB |
testcase_19 | AC | 40 ms
55,792 KB |
testcase_20 | AC | 40 ms
55,636 KB |
testcase_21 | AC | 42 ms
55,772 KB |
testcase_22 | AC | 42 ms
55,968 KB |
testcase_23 | AC | 42 ms
54,808 KB |
testcase_24 | AC | 41 ms
54,924 KB |
testcase_25 | AC | 42 ms
55,228 KB |
testcase_26 | AC | 48 ms
61,660 KB |
testcase_27 | AC | 48 ms
63,048 KB |
testcase_28 | AC | 46 ms
60,752 KB |
testcase_29 | AC | 47 ms
62,192 KB |
testcase_30 | AC | 1,772 ms
93,856 KB |
testcase_31 | AC | 1,748 ms
93,720 KB |
testcase_32 | AC | 1,403 ms
89,444 KB |
testcase_33 | AC | 161 ms
95,672 KB |
testcase_34 | AC | 175 ms
95,424 KB |
testcase_35 | AC | 1,091 ms
95,568 KB |
testcase_36 | AC | 1,181 ms
95,516 KB |
testcase_37 | AC | 1,521 ms
95,804 KB |
testcase_38 | AC | 2,206 ms
95,972 KB |
testcase_39 | AC | 2,284 ms
95,420 KB |
testcase_40 | AC | 737 ms
94,712 KB |
testcase_41 | AC | 1,840 ms
97,620 KB |
testcase_42 | AC | 2,098 ms
93,292 KB |
testcase_43 | AC | 1,841 ms
95,384 KB |
testcase_44 | AC | 1,867 ms
97,400 KB |
testcase_45 | AC | 2,079 ms
93,656 KB |
testcase_46 | AC | 1,799 ms
95,184 KB |
testcase_47 | AC | 2,157 ms
94,888 KB |
testcase_48 | AC | 2,091 ms
93,264 KB |
testcase_49 | AC | 2,140 ms
93,688 KB |
ソースコード
def Manacher(s): dummy = "@" s = dummy+dummy.join(s)+dummy i = j = 0 res = [-1]*len(s) while i < len(s): while i-j >= 0 and i+j < len(s) and s[i-j] == s[i+j]: j += 1 res[i] = j-1 k = 1 while i-k >= 0 and k+res[i-k]+1 < j: res[i+k] = res[i-k] k += 1 i += k j -= k return res def solve(): import sys def SI(): return sys.stdin.readline().rstrip() from random import randrange s = SI() n = len(s) BASE = randrange(128, 256) MOD = (1 << 61)-1 h = [0] pw = [1] for c in s: h += [h[-1]*BASE%MOD+ord(c)] pw += [pw[-1]*BASE%MOD] rh = [0] for c in s[::-1]: rh += [rh[-1]*BASE%MOD+ord(c)] def hash(h, l, r): return (h[r]-h[l]*pw[r-l]%MOD)%MOD dia = Manacher(s) def binary_search(l, r, i, j): if l > r: return 0 if l < 0: l = 0 r += 1 while l+1 < r: m = (l+r)//2 if hash(h, i-m, i) == hash(rh, n-(j+m), n-j): l = m else: r = m return l ans = 1 for i in range(1, n): r = min(i, n-i) if r*2 <= ans: continue d = dia[i*2]//2 if d*2 == n: print(n-1) exit() # delete left ni, nj = i-d-1, i+d r = min(ni, n-nj) if ni >= 0 and (d+r)*2 > ans: e = binary_search(ans//2-d, r, ni, nj) if (d+e)*2 > ans: ans = (d+e)*2 # delete right ni, nj = i-d, i+d+1 r = min(ni, n-nj) if nj <= n and (d+r)*2 > ans: e = binary_search(ans//2-d, r, ni, nj) if (d+e)*2 > ans: ans = (d+e)*2 for i in range(n-1): r = min(i, n-i-1) if r*2+1 <= ans: continue d = dia[i*2+1]//2 if d*2+1 == n: print(n-1) exit() # delete left ni, nj = i-d-1, i+1+d r = min(ni, n-nj) if ni >= 0 and (d+r)*2+1 > ans: e = binary_search((ans-1)//2-d, r, ni, nj) if (d+e)*2+1 > ans: ans = (d+e)*2+1 # delete right ni, nj = i-d, i+d+2 r = min(ni, n-nj) if nj <= n and (d+r)*2+1 > ans: e = binary_search((ans-1)//2-d, r, ni, nj) if (d+e)*2+1 > ans: ans = (d+e)*2+1 print(ans) solve()