結果

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

ソースコード

diff #

def longest_palindrome_after_deletion(s):
    def manacher(s):
        s = '#' + '#'.join(s) + '#'
        n = len(s)
        P = [0] * n
        C, R = 0, 0
        for i in range(n):
            mirror = 2*C - i
            if i < R:
                P[i] = min(R - i, P[mirror])
            a, b = i + (1 + P[i]), i - (1 + P[i])
            while a < n and b >= 0 and s[a] == s[b]:
                P[i] += 1
                a += 1
                b -= 1
            if i + P[i] > R:
                C = i
                R = i + P[i]
        max_len = max(P)
        return max_len

    max_len = 0
    n = len(s)
    if n == 1:
        return 0
    for i in range(n):
        new_s = s[:i] + s[i+1:]
        current_len = manacher(new_s)
        if current_len > max_len:
            max_len = current_len
    return max_len

s = input().strip()
print(longest_palindrome_after_deletion(s))
0