結果

問題 No.1617 Palindrome Removal
ユーザー gew1fw
提出日時 2025-06-12 20:40:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 551 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2025-06-12 20:40:18
合計ジャッジ時間 2,637 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_palindrome(s):
    left = 0
    right = len(s) - 1
    while left < right:
        if s[left] != s[right]:
            return False
        left += 1
        right -= 1
    return True

def all_same(s):
    if not s:
        return True
    first = s[0]
    for c in s:
        if c != first:
            return False
    return True

s = input().strip()
if not is_palindrome(s):
    print(len(s))
else:
    if all_same(s):
        if len(s) % 2 == 0:
            print(0)
        else:
            print(-1)
    else:
        print(len(s) - 2)
0