結果

問題 No.958 たぷりすたべる (回文)
ユーザー treeone
提出日時 2019-12-19 18:09:04
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 749 bytes
コンパイル時間 7,530 ms
コンパイル使用メモリ 258,308 KB
最終ジャッジ日時 2025-01-08 12:47:53
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1 MLE * 1
other WA * 22 RE * 13 TLE * 10 MLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<int> manacher(string s){
    int i = 0, j = 0;
    vector<int> res(s.size());
    while (i < s.size()) {
        while (i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j]) ++j;
        res[i] = j;
        int k = 1;
        while (i - k >= 0 && i + k < s.size() && k + res[i - k] < j) res[i + k] = res[i - k], ++k;
        i += k; j -= k;
    }
    return res;
}

int main(){
    string S;
    ll K, Q;
    cin >> S >> K >> Q;
    ll N = S.size();
    string T = "";
    for(int i = 0; i < K; i++){
        T += S;
    }
    vector<int> A = manacher(T);
    while(Q--){
        int pos;
        cin >> pos;
        pos--;
        cout << A[pos] * 2 - 1 << endl;
    }
}
0