結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー rlangevinrlangevin
提出日時 2023-02-03 22:33:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 644 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 76,948 KB
最終ジャッジ日時 2023-09-15 18:40:22
合計ジャッジ時間 8,588 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,348 KB
testcase_01 AC 73 ms
71,312 KB
testcase_02 AC 74 ms
71,172 KB
testcase_03 AC 185 ms
76,696 KB
testcase_04 AC 108 ms
76,688 KB
testcase_05 AC 98 ms
76,888 KB
testcase_06 AC 227 ms
76,552 KB
testcase_07 AC 215 ms
76,656 KB
testcase_08 AC 204 ms
76,720 KB
testcase_09 AC 368 ms
76,688 KB
testcase_10 AC 228 ms
76,552 KB
testcase_11 AC 202 ms
76,660 KB
testcase_12 AC 230 ms
76,704 KB
testcase_13 AC 229 ms
76,392 KB
testcase_14 AC 228 ms
76,584 KB
testcase_15 AC 221 ms
76,700 KB
testcase_16 AC 142 ms
76,948 KB
testcase_17 AC 159 ms
76,788 KB
testcase_18 AC 227 ms
76,612 KB
testcase_19 AC 229 ms
76,580 KB
testcase_20 AC 229 ms
76,584 KB
testcase_21 AC 228 ms
76,880 KB
testcase_22 AC 227 ms
76,600 KB
testcase_23 AC 230 ms
76,700 KB
testcase_24 AC 232 ms
76,636 KB
testcase_25 AC 230 ms
76,680 KB
testcase_26 AC 230 ms
76,680 KB
testcase_27 AC 182 ms
76,524 KB
testcase_28 AC 229 ms
76,768 KB
testcase_29 AC 226 ms
76,656 KB
testcase_30 AC 72 ms
71,076 KB
testcase_31 AC 72 ms
71,352 KB
testcase_32 AC 266 ms
76,692 KB
testcase_33 AC 230 ms
76,660 KB
testcase_34 AC 73 ms
71,216 KB
testcase_35 AC 269 ms
76,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = list(input())
S = list(map(ord, S))
N = len(S)
inf = 10 ** 18
dp = [inf] * (N + 1)

mod = 2**31 - 1
bb = [1] * (N + 2)
invbb = [1] * (N + 2)
for i in range(1, N + 2):
    bb[i] = bb[i - 1] * 4869 % mod
    invbb[i] = pow(bb[i], mod - 2, mod)
    
b = 4869
invb = pow(b, mod - 2, mod)
SS = [0]

for i in range(1, N + 1):
    val = 0
    rh = SS[i - 1] * b + S[i - 1]
    SS.append(rh%mod)
    pre = 0
    for j in range(i):
        rh2 = pre * b + S[i - j - 1]
        rh2 %= mod
        if rh2 == (rh - SS[i - j - 1] * bb[j + 1]) % mod:
            val = max(val, min(dp[i - j - 1], j + 1))
        pre = rh2
    dp[i] = val
print(dp[-1])  
0