結果

問題 No.1617 Palindrome Removal
ユーザー moharan627moharan627
提出日時 2021-07-22 21:36:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 1,134 ms
コンパイル使用メモリ 10,728 KB
実行使用メモリ 17,620 KB
最終ジャッジ日時 2023-09-24 16:01:03
合計ジャッジ時間 4,489 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 153 ms
17,620 KB
testcase_01 AC 157 ms
17,136 KB
testcase_02 AC 150 ms
16,772 KB
testcase_03 AC 152 ms
17,512 KB
testcase_04 AC 157 ms
17,100 KB
testcase_05 AC 131 ms
16,220 KB
testcase_06 AC 171 ms
17,124 KB
testcase_07 AC 112 ms
13,720 KB
testcase_08 AC 19 ms
8,432 KB
testcase_09 AC 19 ms
8,436 KB
testcase_10 AC 153 ms
17,316 KB
testcase_11 AC 132 ms
15,256 KB
testcase_12 AC 160 ms
17,076 KB
testcase_13 AC 158 ms
17,180 KB
testcase_14 AC 19 ms
8,424 KB
testcase_15 AC 18 ms
8,396 KB
testcase_16 AC 18 ms
8,440 KB
testcase_17 AC 19 ms
8,376 KB
testcase_18 AC 19 ms
8,456 KB
testcase_19 AC 19 ms
8,384 KB
testcase_20 AC 19 ms
8,524 KB
testcase_21 AC 19 ms
8,344 KB
testcase_22 AC 19 ms
8,556 KB
testcase_23 AC 19 ms
8,400 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
    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