結果

問題 No.958 たぷりすたべる (回文)
ユーザー pekempeypekempey
提出日時 2019-12-21 00:08:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 1,122 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 167,896 KB
実行使用メモリ 11,960 KB
最終ジャッジ日時 2023-09-25 05:47:18
合計ジャッジ時間 9,667 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 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 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 136 ms
4,380 KB
testcase_28 AC 136 ms
4,380 KB
testcase_29 AC 138 ms
4,376 KB
testcase_30 AC 136 ms
4,380 KB
testcase_31 AC 137 ms
4,380 KB
testcase_32 AC 139 ms
4,380 KB
testcase_33 AC 138 ms
4,376 KB
testcase_34 AC 136 ms
4,380 KB
testcase_35 AC 136 ms
4,376 KB
testcase_36 AC 137 ms
4,376 KB
testcase_37 AC 128 ms
4,380 KB
testcase_38 AC 128 ms
4,376 KB
testcase_39 AC 131 ms
4,376 KB
testcase_40 AC 127 ms
4,376 KB
testcase_41 AC 131 ms
4,376 KB
testcase_42 AC 126 ms
4,376 KB
testcase_43 AC 129 ms
4,380 KB
testcase_44 AC 129 ms
4,376 KB
testcase_45 AC 129 ms
4,376 KB
testcase_46 AC 131 ms
4,376 KB
testcase_47 AC 301 ms
8,876 KB
testcase_48 AC 312 ms
11,848 KB
testcase_49 AC 310 ms
11,960 KB
testcase_50 AC 320 ms
11,908 KB
testcase_51 AC 312 ms
11,912 KB
testcase_52 AC 314 ms
11,920 KB
testcase_53 AC 312 ms
11,848 KB
testcase_54 AC 310 ms
11,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define rep2r(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

vector<int> manacher(string s) {
  const int n = s.size();
  vector<int> rad(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 (rad[i-j]<k) {
      rad[i+j] = rad[i-j];
      j++; k--;
    }
    i += j;
  }
  return rad;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N, K, Q; cin >> N >> K >> Q;
  string S; cin >> S;
  auto m1 = manacher(S + S + S);
  auto m2 = manacher(S + S + S + S + S);
  while (Q--) {
    ll A; cin >> A; A--;
    ll r1 = m1[A % N + N];
    ll r2 = m2[A % N + 2*N];
    if (r1 != r2) {
      cout << min(A, N*K-1-A)*2+1 << endl;
      continue;
    }
    cout << min(r2, min(A, N*K-1-A))*2+1 << endl;
  }
}
0