結果

問題 No.2234 palindromer
ユーザー hir355hir355
提出日時 2023-03-03 21:40:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 81,528 KB
実行使用メモリ 53,236 KB
最終ジャッジ日時 2023-10-18 01:37:17
合計ジャッジ時間 1,486 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def manacher(S):
    C = []
    for a in S:
        C.append(a)
        C.append(0)
    C.pop()

    L = len(C)

    R = [0]*L

    i = j = 0
    while i < L:
        while j <= i < L-j and C[i-j] == C[i+j]:
            j += 1
        R[i] = j
        k = 1
        while j-R[i-k] > k <= i < L-k:
            R[i+k] = R[i-k]
            k += 1
        i += k; j -= k

    for i in range(L):
        if i & 1 == R[i] & 1:
            R[i] -= 1
    return R

a = input()
r = manacher(a)
for i in range(len(r)):
    if len(r) - r[i] == i:
        print(a + a[:-r[i]][::-1])
        break
0