結果

問題 No.958 たぷりすたべる (回文)
ユーザー pekempeypekempey
提出日時 2019-12-21 02:07:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 648 ms / 2,000 ms
コード長 541 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 86,600 KB
実行使用メモリ 103,032 KB
最終ジャッジ日時 2023-09-25 08:54:17
合計ジャッジ時間 19,006 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,384 KB
testcase_01 AC 71 ms
71,320 KB
testcase_02 AC 71 ms
71,192 KB
testcase_03 AC 76 ms
71,360 KB
testcase_04 AC 75 ms
71,268 KB
testcase_05 AC 71 ms
71,276 KB
testcase_06 AC 73 ms
71,432 KB
testcase_07 AC 72 ms
71,144 KB
testcase_08 AC 72 ms
71,164 KB
testcase_09 AC 72 ms
71,216 KB
testcase_10 AC 74 ms
71,000 KB
testcase_11 AC 73 ms
71,268 KB
testcase_12 AC 74 ms
71,248 KB
testcase_13 AC 71 ms
71,000 KB
testcase_14 AC 71 ms
71,156 KB
testcase_15 AC 72 ms
71,432 KB
testcase_16 AC 72 ms
71,144 KB
testcase_17 AC 72 ms
71,428 KB
testcase_18 AC 73 ms
70,996 KB
testcase_19 AC 75 ms
71,000 KB
testcase_20 AC 75 ms
71,292 KB
testcase_21 AC 76 ms
71,336 KB
testcase_22 AC 77 ms
71,268 KB
testcase_23 AC 76 ms
71,148 KB
testcase_24 AC 76 ms
71,476 KB
testcase_25 AC 77 ms
71,276 KB
testcase_26 AC 77 ms
71,276 KB
testcase_27 AC 299 ms
77,436 KB
testcase_28 AC 284 ms
77,336 KB
testcase_29 AC 284 ms
77,340 KB
testcase_30 AC 286 ms
77,396 KB
testcase_31 AC 284 ms
77,064 KB
testcase_32 AC 288 ms
77,140 KB
testcase_33 AC 291 ms
77,320 KB
testcase_34 AC 288 ms
77,112 KB
testcase_35 AC 282 ms
77,300 KB
testcase_36 AC 286 ms
77,244 KB
testcase_37 AC 274 ms
77,432 KB
testcase_38 AC 279 ms
77,388 KB
testcase_39 AC 283 ms
77,408 KB
testcase_40 AC 280 ms
77,404 KB
testcase_41 AC 278 ms
77,580 KB
testcase_42 AC 282 ms
77,824 KB
testcase_43 AC 267 ms
77,328 KB
testcase_44 AC 279 ms
77,396 KB
testcase_45 AC 277 ms
77,392 KB
testcase_46 AC 285 ms
77,828 KB
testcase_47 AC 514 ms
83,776 KB
testcase_48 AC 542 ms
87,032 KB
testcase_49 AC 600 ms
87,644 KB
testcase_50 AC 535 ms
86,852 KB
testcase_51 AC 648 ms
102,620 KB
testcase_52 AC 626 ms
103,032 KB
testcase_53 AC 603 ms
90,224 KB
testcase_54 AC 611 ms
102,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K, Q = map(int, input().split())

def manacher(s):
  n = len(s)
  rad = [None] * n
  i = 0
  k = 0
  while i < n:
    while i-k-1>=0 and i+k+1<n and s[i-k-1]==s[i+k+1]:
      k += 1
    rad[i] = k
    j = 1
    k -= 1
    while i-j >= 0 and rad[i-j] < k:
      rad[i+j] = rad[i-j]
      j += 1
      k -= 1
    i += j
  return rad

S = input()
rad = manacher(S + S + S + S + S)

for _ in range(Q):
  A = int(input()) - 1
  if rad[A % N + 2*N] >= 2*N:
    print(min(A, N*K-1-A)*2+1)
  else:
    print(min(rad[A % N + 2*N], A, N*K-1-A)*2+1)
0