結果

問題 No.958 たぷりすたべる (回文)
ユーザー nebukuro09nebukuro09
提出日時 2019-12-21 04:25:01
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,180 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 103,764 KB
実行使用メモリ 7,004 KB
最終ジャッジ日時 2023-09-04 04:24:42
合計ジャッジ時間 6,058 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 51 ms
4,376 KB
testcase_28 AC 50 ms
4,380 KB
testcase_29 AC 51 ms
4,380 KB
testcase_30 AC 50 ms
4,376 KB
testcase_31 AC 50 ms
4,380 KB
testcase_32 AC 50 ms
4,376 KB
testcase_33 AC 51 ms
4,384 KB
testcase_34 AC 49 ms
4,376 KB
testcase_35 AC 51 ms
4,380 KB
testcase_36 AC 51 ms
4,380 KB
testcase_37 AC 47 ms
4,380 KB
testcase_38 AC 48 ms
4,376 KB
testcase_39 AC 48 ms
4,380 KB
testcase_40 AC 49 ms
4,380 KB
testcase_41 AC 47 ms
4,380 KB
testcase_42 AC 47 ms
4,380 KB
testcase_43 AC 46 ms
4,376 KB
testcase_44 AC 48 ms
4,376 KB
testcase_45 AC 47 ms
4,376 KB
testcase_46 AC 48 ms
4,380 KB
testcase_47 AC 111 ms
5,872 KB
testcase_48 AC 112 ms
6,964 KB
testcase_49 AC 116 ms
6,932 KB
testcase_50 AC 112 ms
6,904 KB
testcase_51 AC 116 ms
7,004 KB
testcase_52 AC 121 ms
6,956 KB
testcase_53 AC 118 ms
6,948 KB
testcase_54 AC 121 ms
6,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long;
    auto Q = s[2];
    auto S = readln.chomp;

    auto T = S ~ S ~ S;
    auto A = manacher(T);
    auto L = K * N;

    foreach (_; 0..Q) {
        auto idx = readln.chomp.to!long - 1;
        auto rest = min(idx + 1, L - idx);
        auto m = idx % N + N;
        auto v = A[m.to!int];
        auto mr = min(m + 1, 3 * N - m);
        long ans;
        if (v == mr) {
            ans = rest;
        } else {
            ans = v;
        }
        ans = min(ans, rest);
        writeln(ans * 2 - 1);
    }
}

int[] manacher(string s) {
    int n = s.length.to!int;
    auto ret = new int[](n);
    for (int i = 0, j = 0; i < n; ) {
        while (i - j >= 0 && i + j < n && s[i - j] == s[i + j]) ++j;
        ret[i] = j;
        int k = 1;
        while (i - k >= 0 && i + k < n && k + ret[i - k] < j) ret[i + k] = ret[i - k], ++k;
        i += k; j -= k;
    }
    return ret;
}
0