結果
問題 | No.958 たぷりすたべる (回文) |
ユーザー |
![]() |
提出日時 | 2020-01-30 22:44:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 56 ms / 2,000 ms |
コード長 | 819 bytes |
コンパイル時間 | 646 ms |
コンパイル使用メモリ | 72,948 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-16 03:59:31 |
合計ジャッジ時間 | 3,793 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 53 |
ソースコード
#include <vector>#include <iostream>#include <algorithm>using namespace std;int main() {cin.tie(0);ios_base::sync_with_stdio(false);int N, K, Q; string S;cin >> N >> K >> Q >> S;string T = S + S + S;vector<int> len(3 * N);int center = 0;for (int i = 0; i < 3 * N; ++i) {int l = center * 2 - i;if (l >= 0 && i + len[l] < center + len[center]) {len[i] = len[l];}else {int nlen = center + len[center] - i;while (i - nlen >= 0 && i + nlen < 3 * N && T[i + nlen] == T[i - nlen]) {++nlen;}len[i] = nlen;center = i;}}for (int i = 0; i < Q; ++i) {long long ptr;cin >> ptr; --ptr;long long pans = len[N + ptr % N];long long ans = min(ptr + 1, 1LL * K * N - ptr);if (pans <= N) ans = min(ans, pans);cout << ans * 2 - 1 << '\n';}return 0;}