結果

問題 No.958 たぷりすたべる (回文)
ユーザー mkawa2mkawa2
提出日時 2022-06-24 11:20:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 1,384 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,348 KB
実行使用メモリ 82,952 KB
最終ジャッジ日時 2024-04-25 16:01:08
合計ジャッジ時間 7,385 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,912 KB
testcase_01 AC 37 ms
52,676 KB
testcase_02 AC 37 ms
52,896 KB
testcase_03 AC 40 ms
54,176 KB
testcase_04 AC 40 ms
54,292 KB
testcase_05 AC 38 ms
53,304 KB
testcase_06 AC 37 ms
53,196 KB
testcase_07 AC 37 ms
53,476 KB
testcase_08 AC 38 ms
53,256 KB
testcase_09 AC 37 ms
52,748 KB
testcase_10 AC 37 ms
52,744 KB
testcase_11 AC 37 ms
53,136 KB
testcase_12 AC 39 ms
54,248 KB
testcase_13 AC 39 ms
53,096 KB
testcase_14 AC 38 ms
53,424 KB
testcase_15 AC 39 ms
52,536 KB
testcase_16 AC 38 ms
53,140 KB
testcase_17 AC 38 ms
53,476 KB
testcase_18 AC 38 ms
53,416 KB
testcase_19 AC 39 ms
53,256 KB
testcase_20 AC 39 ms
53,252 KB
testcase_21 AC 40 ms
53,780 KB
testcase_22 AC 39 ms
54,676 KB
testcase_23 AC 40 ms
54,468 KB
testcase_24 AC 39 ms
53,260 KB
testcase_25 AC 40 ms
54,648 KB
testcase_26 AC 39 ms
53,268 KB
testcase_27 AC 96 ms
76,404 KB
testcase_28 AC 85 ms
76,508 KB
testcase_29 AC 84 ms
76,376 KB
testcase_30 AC 81 ms
76,264 KB
testcase_31 AC 84 ms
76,192 KB
testcase_32 AC 85 ms
76,132 KB
testcase_33 AC 87 ms
76,284 KB
testcase_34 AC 83 ms
76,180 KB
testcase_35 AC 85 ms
76,172 KB
testcase_36 AC 83 ms
76,276 KB
testcase_37 AC 95 ms
76,232 KB
testcase_38 AC 97 ms
76,192 KB
testcase_39 AC 94 ms
76,124 KB
testcase_40 AC 93 ms
76,192 KB
testcase_41 AC 98 ms
76,128 KB
testcase_42 AC 95 ms
76,260 KB
testcase_43 AC 87 ms
76,316 KB
testcase_44 AC 94 ms
76,400 KB
testcase_45 AC 96 ms
76,404 KB
testcase_46 AC 101 ms
76,644 KB
testcase_47 AC 175 ms
80,616 KB
testcase_48 AC 184 ms
82,696 KB
testcase_49 AC 190 ms
82,780 KB
testcase_50 AC 185 ms
82,952 KB
testcase_51 AC 196 ms
82,580 KB
testcase_52 AC 225 ms
82,580 KB
testcase_53 AC 193 ms
82,264 KB
testcase_54 AC 197 ms
82,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

def Manacher(s):
    i = j = 0
    res = [-1]*len(s)
    while i < len(s):
        while i-j >= 0 and i+j < len(s) and s[i-j] == s[i+j]: j += 1
        res[i] = j
        k = 1
        while i-k >= 0 and k+res[i-k] < j:
            res[i+k] = res[i-k]
            k += 1
        i += k
        j -= k
    return res

n, k, q = LI()
s = SI()

if k < 3:
    ll = Manacher(s*k)
    for _ in range(q):
        i = II()-1
        print(ll[i]*2-1)
    exit()

ll = Manacher(s*3)
for _ in range(q):
    a = II()-1
    j, i = divmod(a, n)
    if j == k-1: i += 2*n
    elif j: i += n
    ans = ll[i]*2-1
    if ans >= n: ans = min(a*2+1, (n*k-a)*2-1)
    print(ans)
0