結果

問題 No.2204 Palindrome Splitting (No Rearrangement ver.)
ユーザー lloyzlloyz
提出日時 2023-02-04 14:09:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,157 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 10,780 KB
実行使用メモリ 12,260 KB
最終ジャッジ日時 2023-09-16 10:56:17
合計ジャッジ時間 7,115 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,260 KB
testcase_01 AC 17 ms
7,900 KB
testcase_02 AC 18 ms
7,896 KB
testcase_03 TLE -
testcase_04 AC 571 ms
8,060 KB
testcase_05 AC 320 ms
7,776 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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