結果

問題 No.1617 Palindrome Removal
ユーザー m1k__m1k__
提出日時 2021-07-22 22:03:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 430 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 86,624 KB
実行使用メモリ 78,076 KB
最終ジャッジ日時 2023-09-24 17:02:46
合計ジャッジ時間 3,691 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
77,732 KB
testcase_01 AC 84 ms
77,672 KB
testcase_02 AC 83 ms
77,528 KB
testcase_03 AC 83 ms
77,728 KB
testcase_04 AC 93 ms
78,028 KB
testcase_05 AC 91 ms
77,520 KB
testcase_06 AC 93 ms
78,076 KB
testcase_07 AC 87 ms
77,060 KB
testcase_08 AC 71 ms
71,036 KB
testcase_09 AC 72 ms
71,088 KB
testcase_10 AC 91 ms
77,672 KB
testcase_11 AC 90 ms
77,600 KB
testcase_12 AC 92 ms
78,016 KB
testcase_13 AC 94 ms
77,980 KB
testcase_14 AC 72 ms
71,132 KB
testcase_15 AC 71 ms
71,300 KB
testcase_16 AC 70 ms
71,392 KB
testcase_17 AC 71 ms
71,032 KB
testcase_18 AC 72 ms
71,180 KB
testcase_19 AC 73 ms
71,368 KB
testcase_20 AC 72 ms
71,132 KB
testcase_21 AC 71 ms
71,100 KB
testcase_22 AC 70 ms
71,336 KB
testcase_23 AC 72 ms
71,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
cnt = [0]*26
f = 1
lenS = len(S)
for i in range(lenS//2):
    si, sj = S[i], S[lenS-1-i]
    f *= si==sj
    cnt[ord(si)-97] += 1
    cnt[ord(sj)-97] += 1
if lenS%2:
    s = S[lenS//2]
    cnt[ord(s)-97] += 1
if f:
    lst = [c for c in cnt if c>0]
    if len(lst)==1:
        print(-1 if lenS%2 else 0)
    else:
        if lenS==3:
            print(-1)
        else:
            print(lenS-2)
else:
    print(lenS)
0