結果
問題 | No.765 ukuku 2 |
ユーザー | mkawa2 |
提出日時 | 2022-02-08 17:01:17 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,976 bytes |
コンパイル時間 | 550 ms |
コンパイル使用メモリ | 82,520 KB |
実行使用メモリ | 93,268 KB |
最終ジャッジ日時 | 2024-06-23 12:21:21 |
合計ジャッジ時間 | 25,281 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
55,840 KB |
testcase_01 | AC | 40 ms
54,316 KB |
testcase_02 | AC | 39 ms
55,128 KB |
testcase_03 | AC | 41 ms
55,412 KB |
testcase_04 | AC | 40 ms
55,408 KB |
testcase_05 | AC | 41 ms
54,428 KB |
testcase_06 | AC | 40 ms
54,432 KB |
testcase_07 | AC | 41 ms
54,824 KB |
testcase_08 | AC | 40 ms
55,456 KB |
testcase_09 | AC | 42 ms
55,000 KB |
testcase_10 | AC | 40 ms
55,284 KB |
testcase_11 | AC | 39 ms
54,960 KB |
testcase_12 | AC | 40 ms
55,028 KB |
testcase_13 | AC | 41 ms
54,900 KB |
testcase_14 | AC | 42 ms
54,952 KB |
testcase_15 | AC | 41 ms
55,104 KB |
testcase_16 | AC | 42 ms
54,724 KB |
testcase_17 | AC | 42 ms
55,200 KB |
testcase_18 | AC | 42 ms
55,888 KB |
testcase_19 | AC | 41 ms
56,380 KB |
testcase_20 | AC | 41 ms
55,244 KB |
testcase_21 | AC | 40 ms
55,268 KB |
testcase_22 | AC | 40 ms
55,136 KB |
testcase_23 | AC | 41 ms
56,440 KB |
testcase_24 | AC | 42 ms
55,528 KB |
testcase_25 | AC | 41 ms
55,852 KB |
testcase_26 | AC | 50 ms
64,140 KB |
testcase_27 | AC | 50 ms
64,264 KB |
testcase_28 | AC | 48 ms
64,080 KB |
testcase_29 | AC | 50 ms
65,988 KB |
testcase_30 | AC | 2,541 ms
90,920 KB |
testcase_31 | AC | 2,477 ms
89,840 KB |
testcase_32 | AC | 2,035 ms
88,476 KB |
testcase_33 | AC | 455 ms
92,368 KB |
testcase_34 | AC | 463 ms
92,360 KB |
testcase_35 | AC | 1,615 ms
92,108 KB |
testcase_36 | AC | 1,769 ms
92,112 KB |
testcase_37 | AC | 2,692 ms
91,980 KB |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | AC | 1,047 ms
91,392 KB |
testcase_41 | AC | 2,655 ms
93,268 KB |
testcase_42 | TLE | - |
testcase_43 | AC | 2,654 ms
90,776 KB |
testcase_44 | AC | 2,693 ms
91,520 KB |
testcase_45 | TLE | - |
testcase_46 | AC | 2,634 ms
90,976 KB |
testcase_47 | TLE | - |
testcase_48 | TLE | - |
testcase_49 | TLE | - |
ソースコード
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 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 = binary_search(0, r, i, i) 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 = binary_search(0, r, i, i+1) 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()