結果

問題 No.1617 Palindrome Removal
ユーザー moharan627moharan627
提出日時 2021-07-22 21:30:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,012 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 17,432 KB
最終ジャッジ日時 2023-09-24 15:49:08
合計ジャッジ時間 3,370 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
17,372 KB
testcase_01 AC 157 ms
17,116 KB
testcase_02 AC 150 ms
16,500 KB
testcase_03 AC 151 ms
17,432 KB
testcase_04 AC 158 ms
17,248 KB
testcase_05 AC 128 ms
16,072 KB
testcase_06 AC 172 ms
17,132 KB
testcase_07 AC 112 ms
13,708 KB
testcase_08 AC 19 ms
8,400 KB
testcase_09 AC 19 ms
8,340 KB
testcase_10 AC 149 ms
17,392 KB
testcase_11 AC 132 ms
15,324 KB
testcase_12 AC 159 ms
17,180 KB
testcase_13 AC 161 ms
17,140 KB
testcase_14 AC 18 ms
8,404 KB
testcase_15 AC 18 ms
8,556 KB
testcase_16 AC 19 ms
8,424 KB
testcase_17 AC 19 ms
8,404 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 18 ms
8,400 KB
testcase_21 AC 18 ms
8,336 KB
testcase_22 AC 18 ms
8,492 KB
testcase_23 AC 19 ms
8,528 KB
権限があれば一括ダウンロードができます

ソースコード

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