結果

問題 No.958 たぷりすたべる (回文)
ユーザー risujirohrisujiroh
提出日時 2019-12-21 00:45:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 172,172 KB
実行使用メモリ 15,064 KB
最終ジャッジ日時 2023-09-25 06:40:04
合計ジャッジ時間 7,036 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 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,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 23 ms
4,376 KB
testcase_28 AC 26 ms
4,380 KB
testcase_29 AC 23 ms
4,376 KB
testcase_30 AC 21 ms
4,384 KB
testcase_31 AC 23 ms
4,376 KB
testcase_32 AC 25 ms
4,380 KB
testcase_33 AC 27 ms
4,376 KB
testcase_34 AC 25 ms
4,376 KB
testcase_35 AC 27 ms
4,380 KB
testcase_36 AC 25 ms
4,384 KB
testcase_37 AC 16 ms
4,376 KB
testcase_38 AC 20 ms
4,380 KB
testcase_39 AC 20 ms
4,380 KB
testcase_40 AC 23 ms
4,380 KB
testcase_41 AC 21 ms
4,376 KB
testcase_42 AC 27 ms
4,376 KB
testcase_43 AC 27 ms
4,376 KB
testcase_44 AC 28 ms
4,380 KB
testcase_45 AC 28 ms
4,376 KB
testcase_46 AC 25 ms
4,380 KB
testcase_47 AC 193 ms
11,720 KB
testcase_48 AC 213 ms
15,052 KB
testcase_49 AC 234 ms
14,988 KB
testcase_50 AC 215 ms
14,960 KB
testcase_51 AC 256 ms
15,036 KB
testcase_52 AC 234 ms
15,036 KB
testcase_53 AC 250 ms
15,064 KB
testcase_54 AC 255 ms
14,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct RollingHash {
  static constexpr long long m31 = (1LL << 31) - 1;
  static int mod_m31(long long a) {
    a = (a >> 31) + (a & m31);
    return a >= m31 ? a - m31 : a;
  }
  static long long base[2];
  static vector<int> powb[2];
  vector<int> h[2];
  RollingHash(const string& s) : h{{0}, {0}} {
    for (int k : {0, 1}) {
      for (char c : s) h[k].push_back(mod_m31(h[k].back() * base[k] + c));
      while (powb[k].size() <= s.size())
        powb[k].push_back(mod_m31(powb[k].back() * base[k]));
    }
  }
  int get(int l, int r, int k) const {
    return mod_m31(h[k][r] + (m31 - h[k][l]) * powb[k][r - l]);
  }
  auto get(int l, int r) const { return make_pair(get(l, r, 0), get(l, r, 1)); }
};
long long RollingHash::base[2] = {1095803926, 1410736294};
vector<int> RollingHash::powb[2] = {{1}, {1}};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, k, q;
  cin >> n >> k >> q;
  string s;
  cin >> s;
  RollingHash rh(s + s);
  reverse(begin(s), end(s));
  RollingHash rev(s + s);
  while (q--) {
    long long a;
    cin >> a;
    --a;
    long long b = k * n - a - 1;
    int ok = 1, ng = n + 1;
    while (ng - ok > 1) {
      int mid = (ok + ng) / 2;
      (rh.get(a % n, a % n + mid) == rev.get(b % n, b % n + mid) ? ok : ng) = mid;
    }
    long long res = ok < n ? 2 * ok - 1 : k * n;
    res = min(res, 2 * min(k * n - a, a + 1) - 1);
    cout << res << '\n';
  }
}
0