結果

問題 No.2234 palindromer
ユーザー FromBooskaFromBooska
提出日時 2023-03-04 01:37:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 81,744 KB
実行使用メモリ 53,516 KB
最終ジャッジ日時 2023-10-18 04:05:44
合計ジャッジ時間 1,796 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,516 KB
testcase_01 AC 37 ms
53,516 KB
testcase_02 AC 38 ms
53,516 KB
testcase_03 AC 37 ms
53,516 KB
testcase_04 AC 41 ms
53,516 KB
testcase_05 AC 38 ms
53,516 KB
testcase_06 AC 38 ms
53,516 KB
testcase_07 AC 37 ms
53,516 KB
testcase_08 AC 37 ms
53,516 KB
testcase_09 AC 37 ms
53,516 KB
testcase_10 AC 37 ms
53,516 KB
testcase_11 AC 38 ms
53,516 KB
testcase_12 AC 38 ms
53,516 KB
testcase_13 AC 37 ms
53,516 KB
testcase_14 AC 38 ms
53,516 KB
testcase_15 AC 39 ms
53,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

A = input()
N = len(A)
mid_start = N//2
ans1 = 'X'*300
ans2 = 'X'*300

# 中心が1文字の場合と2文字の場合がある
for mid in range(mid_start, N):
    post_mid = A[mid:]
    pre_mid = A[mid+1-(N-mid):mid+1][::-1]
    #print('mid', mid, post_mid, pre_mid)
    if post_mid == pre_mid:
        ans1 = A + A[:mid+1-(N-mid)][::-1]
        #print(ans1)
        break
    
for mid in range(mid_start, N):
    post_mid = A[mid:]
    pre_mid = A[mid-(N-mid):mid][::-1]
    #print('mid', mid, post_mid, pre_mid)
    if post_mid == pre_mid:
        ans2 = A + A[:mid-(N-mid)][::-1]
        #print(ans2)
        break
        
if len(ans1) <= len(ans2):
    print(ans1)
else:
    print(ans2)
0