結果

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

ソースコード

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
    if N==3:
        if (S[0] == S[2]) and S[0] != S[1]:
            print(-1)
            exit()
    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