結果
| 問題 | 
                            No.958 たぷりすたべる (回文)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             square1001
                         | 
                    
| 提出日時 | 2020-01-30 22:42:45 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 790 bytes | 
| コンパイル時間 | 678 ms | 
| コンパイル使用メモリ | 74,096 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-16 03:59:26 | 
| 合計ジャッジ時間 | 4,905 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 22 WA * 31 | 
ソースコード
#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({ pans, ptr + 1, 1LL * K * N - ptr });
		cout << ans * 2 - 1 << '\n';
	}
	return 0;
}
            
            
            
        
            
square1001