結果

問題 No.765 ukuku 2
ユーザー gew1fw
提出日時 2025-06-12 14:14:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 937 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,488 KB
実行使用メモリ 81,304 KB
最終ジャッジ日時 2025-06-12 14:14:36
合計ジャッジ時間 3,997 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

def longest_palindrome(s):
    # Transform s into T with special characters
    T = '#'.join('^{}$'.format(s))
    n = len(T)
    P = [0] * n
    C = R = 0
    max_len = 0

    for i in range(1, n - 1):
        # Find the mirror of the current index
        mirror = 2 * C - i

        # Check if the current index is within the right boundary
        if i < R:
            P[i] = min(R - i, P[mirror])

        # Attempt to expand palindrome centered at i
        while T[i + P[i] + 1] == T[i - P[i] - 1]:
            P[i] += 1

        # Update the center and right boundary if the palindrome expands past R
        if i + P[i] > R:
            C, R = i, i + P[i]

        # Update the maximum length found
        if P[i] > max_len:
            max_len = P[i]

    return max_len

s = input().strip()
n = len(s)
if n == 0:
    print(0)
else:
    L = longest_palindrome(s)
    if L == n:
        print(L - 1)
    else:
        print(L)
0