結果

問題 No.273 回文分解
ユーザー matsu7874
提出日時 2015-08-29 01:34:14
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-06-25 13:26:14
合計ジャッジ時間 2,290 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_palindrome(s):
    if s == s[::-1]:
        return True
    else:
        return False


def longest_palindrome_length(s):
    n = len(s)
    i = 0
    j = 0
    max_rad = 0
    rad = [0 for i in range(2 * n)]
    while i < 2 * n:
        while 0 <= i - j and i + j + 1 < 2 * n and s[(i - j) // 2] == s[(i + j + 1) // 2]:
            j += 1
        rad[i] = j
        max_rad = max(max_rad, j)
        k = 1
        while 0 <= i - k and 0 <= rad[i] - k and rad[i - k] < rad[i] - k:
            rad[i + k] = min(rad[i - k], rad[i] - k)
            k += 1
        i += k
        j = max(j - k, 0)
    return max_rad

S = input()
if is_palindrome(S):
    print(longest_palindrome_length(S[1:]))
else:
    print(longest_palindrome_length(S))
0