結果

問題 No.958 たぷりすたべる (回文)
ユーザー pekempeypekempey
提出日時 2019-12-21 11:51:41
言語 Nim
(2.0.2)
結果
AC  
実行時間 369 ms / 2,000 ms
コード長 710 bytes
コンパイル時間 4,573 ms
コンパイル使用メモリ 71,916 KB
実行使用メモリ 20,228 KB
最終ジャッジ日時 2023-09-26 10:27:00
合計ジャッジ時間 13,744 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,504 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 159 ms
4,376 KB
testcase_28 AC 157 ms
4,376 KB
testcase_29 AC 159 ms
4,380 KB
testcase_30 AC 160 ms
4,380 KB
testcase_31 AC 161 ms
4,376 KB
testcase_32 AC 158 ms
4,376 KB
testcase_33 AC 159 ms
4,376 KB
testcase_34 AC 159 ms
4,376 KB
testcase_35 AC 166 ms
4,376 KB
testcase_36 AC 156 ms
4,376 KB
testcase_37 AC 146 ms
4,376 KB
testcase_38 AC 145 ms
4,376 KB
testcase_39 AC 150 ms
4,376 KB
testcase_40 AC 146 ms
4,380 KB
testcase_41 AC 144 ms
4,376 KB
testcase_42 AC 144 ms
4,376 KB
testcase_43 AC 146 ms
4,380 KB
testcase_44 AC 147 ms
4,376 KB
testcase_45 AC 147 ms
4,376 KB
testcase_46 AC 148 ms
4,380 KB
testcase_47 AC 348 ms
14,428 KB
testcase_48 AC 353 ms
20,196 KB
testcase_49 AC 355 ms
20,228 KB
testcase_50 AC 350 ms
20,224 KB
testcase_51 AC 369 ms
20,220 KB
testcase_52 AC 369 ms
20,176 KB
testcase_53 AC 361 ms
20,156 KB
testcase_54 AC 362 ms
20,224 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import strutils
import sequtils

proc manacher(s: string): seq[int] = 
  let n = s.len
  var rad = newSeq[int](n)
  var i = 0
  var 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
    var 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

let tmp = stdin.readLine.split
let N = tmp[0].parseInt
let K = tmp[1].parseInt
let Q = tmp[2].parseInt
let S = stdin.readLine
let rad = manacher(S & S & S & S & S)

for _ in 0..<Q:
  let A = stdin.readLine.parseInt - 1
  let r = rad[A mod N + 2*N]
  if r >= 2*N:
    echo(min(A, N*K-1-A)*2+1)
  else:
    echo(min(A, min(N*K-1-A, r))*2+1)
0