結果

問題 No.238 Mr. K's Another Gift
ユーザー roaris
提出日時 2019-12-06 10:27:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-12-23 05:03:25
合計ジャッジ時間 4,459 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_palindrome(l, r):
    s_sub = s[l:r+1]
    return s_sub==s_sub[::-1]

s = input()

if is_palindrome(0, len(s)-1):
    if len(s)%2==0:
        print(s[:len(s)//2]+'a'+s[len(s)//2:])
    else:
        print(s[:len(s)//2]+s[len(s)//2]+s[len(s)//2:])
    exit()
    
l, r = 0, len(s)-1

while True:
    if s[l]==s[r]:
        l += 1
        r -= 1
    else:
        if is_palindrome(l+1, r):
            print(s[:r+1]+s[l]+s[r+1:])
        elif is_palindrome(l, r-1):
            print(s[:l]+s[r]+s[l:])
        else:
            print('NA')
        exit()
0