結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー titiatitia
提出日時 2023-02-04 01:08:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 776 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2023-09-15 21:34:11
合計ジャッジ時間 9,407 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,592 KB
testcase_01 AC 72 ms
71,388 KB
testcase_02 AC 73 ms
71,572 KB
testcase_03 AC 190 ms
76,780 KB
testcase_04 AC 118 ms
76,740 KB
testcase_05 AC 102 ms
76,848 KB
testcase_06 AC 257 ms
76,876 KB
testcase_07 AC 239 ms
76,464 KB
testcase_08 AC 224 ms
76,708 KB
testcase_09 AC 233 ms
76,828 KB
testcase_10 AC 261 ms
76,688 KB
testcase_11 AC 227 ms
76,424 KB
testcase_12 AC 256 ms
76,680 KB
testcase_13 AC 257 ms
76,756 KB
testcase_14 AC 259 ms
77,440 KB
testcase_15 AC 245 ms
76,448 KB
testcase_16 AC 156 ms
76,768 KB
testcase_17 AC 173 ms
76,408 KB
testcase_18 AC 255 ms
76,772 KB
testcase_19 AC 257 ms
76,808 KB
testcase_20 AC 258 ms
76,528 KB
testcase_21 AC 259 ms
76,772 KB
testcase_22 AC 258 ms
76,652 KB
testcase_23 AC 258 ms
76,684 KB
testcase_24 AC 256 ms
76,756 KB
testcase_25 AC 262 ms
77,252 KB
testcase_26 AC 260 ms
77,312 KB
testcase_27 AC 201 ms
76,536 KB
testcase_28 AC 258 ms
76,436 KB
testcase_29 AC 257 ms
76,768 KB
testcase_30 AC 74 ms
71,408 KB
testcase_31 AC 73 ms
71,312 KB
testcase_32 AC 277 ms
76,896 KB
testcase_33 AC 257 ms
76,468 KB
testcase_34 AC 73 ms
71,160 KB
testcase_35 AC 283 ms
76,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

S=list(input().strip())

# Manacher
# https://snuke.hatenablog.com/entry/2014/12/02/235837

T=[]
for s in S:
    T.append(s)
    T.append("0")

LEN=len(T)
i=0
j=0
R=[0]*LEN # 文字 i を中心とする最長の回文の半径

while i<LEN:
    while i-j>=0 and i+j<LEN and T[i-j]==T[i+j]:
        j+=1
    R[i]=j
    
    k=1
    while i-k>=0 and i+k<LEN and k+R[i-k]<j:
        R[i+k]=R[i-k]
        k+=1

    i+=k
    j-=k

def pali(x,y):
    l=2*x
    r=2*y
    mid=(l+r)//2
    if R[mid]>=mid-l+1:
        return True
    else:
        return False
    


DP=[0]*(len(S)+1)
DP[0]=1<<60
for i in range(len(S)):
    for j in range(i,len(S)):
        if pali(i,j)==True:
            DP[j+1]=max(DP[j+1],min(DP[i],j+1-i))

print(DP[-1])
0