結果
| 問題 | No.1617 Palindrome Removal | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-04-16 00:07:25 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 493 bytes | 
| コンパイル時間 | 604 ms | 
| コンパイル使用メモリ | 81,468 KB | 
| 実行使用メモリ | 76,012 KB | 
| 最終ジャッジ日時 | 2025-04-16 00:08:42 | 
| 合計ジャッジ時間 | 2,527 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 18 WA * 2 | 
ソースコード
def is_palindrome(s):
    n = len(s)
    for i in range(n // 2):
        if s[i] != s[n - 1 - i]:
            return False
    return True
def all_same(s):
    if not s:
        return True
    c = s[0]
    for char in s:
        if char != c:
            return False
    return True
s = input().strip()
n = len(s)
if not is_palindrome(s):
    print(n)
else:
    if all_same(s):
        if n % 2 == 0:
            print(0)
        else:
            print(-1)
    else:
        print(n - 2)
            
            
            
        