結果

問題 No.238 Mr. K's Another Gift
ユーザー sugar_sentansugar_sentan
提出日時 2019-12-12 20:49:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,071 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 8,640 KB
最終ジャッジ日時 2023-09-07 21:23:09
合計ジャッジ時間 3,438 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,104 KB
testcase_01 AC 16 ms
8,148 KB
testcase_02 AC 16 ms
8,028 KB
testcase_03 AC 16 ms
8,028 KB
testcase_04 AC 18 ms
8,040 KB
testcase_05 AC 39 ms
8,148 KB
testcase_06 AC 40 ms
8,208 KB
testcase_07 AC 46 ms
8,492 KB
testcase_08 AC 48 ms
8,320 KB
testcase_09 AC 57 ms
8,224 KB
testcase_10 AC 15 ms
7,808 KB
testcase_11 AC 16 ms
7,848 KB
testcase_12 AC 16 ms
8,000 KB
testcase_13 AC 16 ms
7,968 KB
testcase_14 AC 27 ms
8,224 KB
testcase_15 AC 44 ms
8,252 KB
testcase_16 AC 44 ms
8,240 KB
testcase_17 AC 17 ms
8,620 KB
testcase_18 AC 22 ms
8,408 KB
testcase_19 AC 16 ms
8,220 KB
testcase_20 AC 16 ms
8,208 KB
testcase_21 AC 16 ms
8,148 KB
testcase_22 AC 16 ms
8,156 KB
testcase_23 AC 16 ms
8,060 KB
testcase_24 AC 18 ms
8,152 KB
testcase_25 AC 21 ms
8,144 KB
testcase_26 AC 39 ms
8,264 KB
testcase_27 AC 56 ms
8,424 KB
testcase_28 AC 39 ms
8,244 KB
testcase_29 AC 55 ms
8,188 KB
testcase_30 AC 16 ms
7,812 KB
testcase_31 AC 16 ms
7,920 KB
testcase_32 AC 16 ms
7,792 KB
testcase_33 AC 17 ms
8,052 KB
testcase_34 AC 16 ms
8,260 KB
testcase_35 AC 39 ms
8,440 KB
testcase_36 AC 23 ms
8,640 KB
testcase_37 AC 32 ms
8,420 KB
testcase_38 AC 22 ms
8,560 KB
testcase_39 AC 16 ms
8,280 KB
testcase_40 AC 15 ms
8,084 KB
testcase_41 AC 15 ms
8,144 KB
testcase_42 AC 15 ms
7,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
N = len(S)
flag = True
for i in range(N):
    if S[i] != S[N-1-i]:
        flag = False
        break
index = i
# 引っかかったインデックスが手に入る
# S[i]をS[len(S)-1-i]の後ろに挿入するか, S[len(S)-1-i]をS[i]の前に挿入するかの二択
if flag:
    print(S[:N//2]+S[N//2]+S[N//2:])
    exit()
else:
    # 引っかかった場所の前にS[len(S)-1-i]を挿入するパターン
    # iが0の時に困る
    if index == 0:
        tmp_s = S[N-1-index]+S[index:]
    else:
        tmp_s = S[:index]+S[N-1-index]+S[index:]
    N = len(tmp_s)
    for j in range(len(tmp_s)):
        if tmp_s[j] != tmp_s[N-1-j]:
            break
    else:
        print(tmp_s)
        exit()
    N -= 1
    # S[i]をS[len(S)-1-i]の後ろに挿入するパターン
    if index == 0:
        tmp_s = S + S[index]
    else:
        tmp_s = S[:N-index]+S[index]+S[N-1-index+1:]
    N = len(tmp_s)
    for k in range(len(tmp_s)):
        if tmp_s[k] != tmp_s[N-1-k]:
            break
    else:
        print(tmp_s)
        exit()
print("NA")
0