結果

問題 No.958 たぷりすたべる (回文)
ユーザー pekempeypekempey
提出日時 2019-12-21 11:01:01
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 179 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 1,281 ms
コンパイル使用メモリ 140,752 KB
実行使用メモリ 9,692 KB
最終ジャッジ日時 2023-09-04 04:24:50
合計ジャッジ時間 6,900 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 62 ms
4,376 KB
testcase_28 AC 61 ms
4,376 KB
testcase_29 AC 61 ms
4,380 KB
testcase_30 AC 61 ms
4,376 KB
testcase_31 AC 60 ms
4,380 KB
testcase_32 AC 61 ms
4,380 KB
testcase_33 AC 61 ms
4,380 KB
testcase_34 AC 61 ms
4,380 KB
testcase_35 AC 61 ms
4,380 KB
testcase_36 AC 61 ms
4,376 KB
testcase_37 AC 60 ms
4,376 KB
testcase_38 AC 63 ms
4,380 KB
testcase_39 AC 62 ms
4,376 KB
testcase_40 AC 62 ms
4,380 KB
testcase_41 AC 62 ms
4,376 KB
testcase_42 AC 61 ms
4,376 KB
testcase_43 AC 60 ms
4,376 KB
testcase_44 AC 62 ms
4,376 KB
testcase_45 AC 61 ms
4,380 KB
testcase_46 AC 63 ms
4,380 KB
testcase_47 AC 161 ms
6,336 KB
testcase_48 AC 168 ms
9,008 KB
testcase_49 AC 170 ms
9,692 KB
testcase_50 AC 168 ms
8,904 KB
testcase_51 AC 172 ms
8,896 KB
testcase_52 AC 179 ms
8,824 KB
testcase_53 AC 172 ms
9,132 KB
testcase_54 AC 172 ms
8,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.algorithm;

int[] manacher(string s) {
  immutable ulong n = s.length;
  int[] rad = new int[n];
  int i = 0;
  int k = 0;
  while (i < n) {
    while (i-k-1>=0 && i+k+1<n && s[i-k-1]==s[i+k+1]) k++;
    rad[i] = k;
    int j = 1;
    k--;
    while (i-j>=0 && rad[i-j]<k) {
      rad[i+j] = rad[i-j];
      j++;
      k--;
    }
    i += j;
  }
  return rad;
}

void main() {
  long N, K, Q;
  readf("%d %d %d\n", &N, &K, &Q);
  string S;
  readf("%s\n", S);
  int[] rad = manacher(S ~ S ~ S ~ S ~ S);
  foreach (_; 0..Q) {
    long A;
    readf("%d\n", &A);
    A--;
    int r = rad[A % N + 2*N];
    if (r >= 2*N) {
      writeln(min(A, N*K-1-A)*2+1);
    } else {
      writeln(min(A, N*K-1-A, r)*2+1);
    }
  }
}
0