結果

問題 No.1617 Palindrome Removal
ユーザー moharan627
提出日時 2021-07-22 21:30:50
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,012 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 19,876 KB
最終ジャッジ日時 2024-07-17 16:35:02
合計ジャッジ時間 4,043 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = float('inf')
#10**20,2**63,float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
from collections import defaultdict
def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())
    S = LC()
    N = len(S)
    C = defaultdict(lambda:0)
    Flag = True
    for n in range(N):
        C[S[n]] = 1
        if(S[n] != S[N-n-1]):
            Flag = False
    if not Flag:
        print(N)
        exit()
    
    #以下は回文
    if sum(list(C.values())) >=2:#2文字以上使われてたら,元の長さから良い感じに2個消せばいい.
        print(N-2)
        exit()

    #以下は使われる文字が1種類
    if N%2 == 1:
        print(-1)
    else:
        print(0)

    return
solve()
#sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!
0