結果

問題 No.958 たぷりすたべる (回文)
ユーザー maspymaspy
提出日時 2020-05-12 01:44:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 919 ms / 2,000 ms
コード長 809 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 43,360 KB
最終ジャッジ日時 2023-09-26 19:11:31
合計ジャッジ時間 19,775 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,944 KB
testcase_01 AC 16 ms
7,676 KB
testcase_02 AC 16 ms
7,760 KB
testcase_03 AC 17 ms
7,804 KB
testcase_04 AC 17 ms
7,756 KB
testcase_05 AC 16 ms
7,772 KB
testcase_06 AC 16 ms
7,940 KB
testcase_07 AC 16 ms
7,816 KB
testcase_08 AC 16 ms
7,752 KB
testcase_09 AC 16 ms
7,752 KB
testcase_10 AC 16 ms
7,828 KB
testcase_11 AC 16 ms
7,744 KB
testcase_12 AC 16 ms
7,800 KB
testcase_13 AC 16 ms
7,744 KB
testcase_14 AC 16 ms
7,820 KB
testcase_15 AC 16 ms
7,880 KB
testcase_16 AC 16 ms
7,804 KB
testcase_17 AC 16 ms
7,888 KB
testcase_18 AC 16 ms
7,776 KB
testcase_19 AC 17 ms
7,752 KB
testcase_20 AC 16 ms
7,828 KB
testcase_21 AC 17 ms
7,824 KB
testcase_22 AC 17 ms
7,828 KB
testcase_23 AC 17 ms
7,776 KB
testcase_24 AC 17 ms
7,760 KB
testcase_25 AC 16 ms
7,756 KB
testcase_26 AC 17 ms
7,748 KB
testcase_27 AC 224 ms
13,976 KB
testcase_28 AC 226 ms
13,948 KB
testcase_29 AC 218 ms
13,988 KB
testcase_30 AC 217 ms
13,988 KB
testcase_31 AC 219 ms
13,988 KB
testcase_32 AC 221 ms
13,980 KB
testcase_33 AC 221 ms
14,080 KB
testcase_34 AC 221 ms
13,988 KB
testcase_35 AC 219 ms
13,912 KB
testcase_36 AC 220 ms
14,084 KB
testcase_37 AC 206 ms
13,696 KB
testcase_38 AC 211 ms
13,700 KB
testcase_39 AC 213 ms
13,760 KB
testcase_40 AC 213 ms
13,796 KB
testcase_41 AC 208 ms
13,860 KB
testcase_42 AC 207 ms
13,784 KB
testcase_43 AC 207 ms
13,668 KB
testcase_44 AC 204 ms
13,780 KB
testcase_45 AC 213 ms
13,724 KB
testcase_46 AC 214 ms
13,616 KB
testcase_47 AC 684 ms
22,800 KB
testcase_48 AC 810 ms
24,716 KB
testcase_49 AC 809 ms
25,020 KB
testcase_50 AC 814 ms
24,684 KB
testcase_51 AC 918 ms
42,888 KB
testcase_52 AC 854 ms
43,360 KB
testcase_53 AC 836 ms
30,888 KB
testcase_54 AC 919 ms
43,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def Manacher(S):
    L = len(S)
    R = [0] * L
    i = 0; j = 0
    while i < L:
        while (i >= j) and (i + j < L) and (S[i-j] == S[i+j]):
            j += 1
        R[i] = j
        k = 1
        while (i >= k) and (i + k < L) and (k + R[i-k] < j):
            R[i + k] = R[i - k]
            k += 1
        i += k
        j -= k
    return R

N,K,Q = map(int, readline().split())
S = readline().rstrip()
A = map(int, read().split())

M = Manacher(S*3)

for x in A:
    x -= 1
    nl = x + 1
    nr = N * K - x
    q, r = divmod(x, N)
    l = M[N + r]
    if l in [N + r + 1, 2 * N - r]:
        n = min(nl, nr)
        print(2 * n - 1)
    else:
        print(2 * min(l, nl, nr) - 1)
0