結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー lloyzlloyz
提出日時 2023-02-04 14:09:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,157 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 86,804 KB
実行使用メモリ 77,792 KB
最終ジャッジ日時 2023-09-16 10:55:56
合計ジャッジ時間 6,686 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,220 KB
testcase_01 AC 68 ms
71,400 KB
testcase_02 AC 71 ms
71,276 KB
testcase_03 AC 129 ms
77,432 KB
testcase_04 AC 99 ms
77,404 KB
testcase_05 AC 96 ms
76,632 KB
testcase_06 AC 160 ms
77,488 KB
testcase_07 AC 151 ms
77,188 KB
testcase_08 AC 147 ms
76,976 KB
testcase_09 AC 148 ms
77,340 KB
testcase_10 AC 156 ms
77,696 KB
testcase_11 AC 148 ms
77,408 KB
testcase_12 AC 154 ms
77,540 KB
testcase_13 AC 153 ms
77,424 KB
testcase_14 AC 160 ms
77,696 KB
testcase_15 AC 149 ms
77,304 KB
testcase_16 AC 116 ms
77,500 KB
testcase_17 AC 124 ms
77,080 KB
testcase_18 AC 159 ms
77,452 KB
testcase_19 AC 160 ms
77,504 KB
testcase_20 AC 158 ms
77,700 KB
testcase_21 AC 157 ms
77,624 KB
testcase_22 AC 155 ms
77,664 KB
testcase_23 AC 156 ms
77,720 KB
testcase_24 AC 157 ms
77,488 KB
testcase_25 AC 159 ms
77,556 KB
testcase_26 AC 158 ms
77,440 KB
testcase_27 AC 137 ms
77,300 KB
testcase_28 AC 157 ms
77,616 KB
testcase_29 AC 158 ms
77,792 KB
testcase_30 AC 67 ms
71,616 KB
testcase_31 AC 68 ms
71,400 KB
testcase_32 AC 195 ms
77,004 KB
testcase_33 AC 155 ms
77,552 KB
testcase_34 AC 68 ms
71,276 KB
testcase_35 AC 204 ms
77,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

s = input()

n = len(s)
t = ""
for ss in s:
    t += ss
    t += '0'

def manacher(S):
    # 最長回文 O(n)
    # R[i] := i 文字目を中心とする最長の回文の半径(自身を含む)
    # 偶数長の回文を検出するには "$a$b$a$a$b$" のようにダミーを挟む
    # 検証: https://atcoder.jp/contests/wupc2019/submissions/8665857
    # 左右で違う条件: https://atcoder.jp/contests/code-thanks-festival-2014-a-open/submissions/12911822
    c, r, n = 0, 0, len(S)  # center, radius, length
    R = [0]*n
    while c < n:
        while c-r >= 0 and c+r < n and S[c-r] == S[c+r]:
            r += 1
        R[c] = r
        d = 1  # distance from center
        while c-d >= 0 and c+d < n and d+R[c-d] < r:
            R[c+d] = R[c-d]
            d += 1
        c += d
        r -= d
    return R

R = manacher(t)

def is_palindrome(x, y):
    l = 2 * x
    r = 2 * y
    mid = (l + r) // 2
    return R[mid] >= mid - l + 1

DP = [0 for _ in range(n + 1)]
DP[0] = 10**18
for i in range(n):
    for j in range(i, n):
        if is_palindrome(i, j):
            DP[j + 1] = max(DP[j + 1], min(DP[i], j - i + 1))
print(DP[n])
0