結果

問題 No.958 たぷりすたべる (回文)
ユーザー tarattata1tarattata1
提出日時 2019-12-21 00:35:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 78,256 KB
実行使用メモリ 5,932 KB
最終ジャッジ日時 2023-09-25 06:18:50
合計ジャッジ時間 4,904 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 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,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 21 ms
4,376 KB
testcase_28 AC 21 ms
4,380 KB
testcase_29 AC 21 ms
4,376 KB
testcase_30 AC 20 ms
4,376 KB
testcase_31 AC 21 ms
4,376 KB
testcase_32 AC 21 ms
4,376 KB
testcase_33 AC 21 ms
4,380 KB
testcase_34 AC 21 ms
4,376 KB
testcase_35 AC 20 ms
4,380 KB
testcase_36 AC 21 ms
4,376 KB
testcase_37 AC 21 ms
4,376 KB
testcase_38 AC 22 ms
4,376 KB
testcase_39 AC 21 ms
4,376 KB
testcase_40 AC 22 ms
4,376 KB
testcase_41 AC 22 ms
4,380 KB
testcase_42 AC 22 ms
4,376 KB
testcase_43 AC 21 ms
4,376 KB
testcase_44 AC 22 ms
4,380 KB
testcase_45 AC 22 ms
4,380 KB
testcase_46 AC 22 ms
4,380 KB
testcase_47 AC 57 ms
4,816 KB
testcase_48 AC 61 ms
5,932 KB
testcase_49 AC 62 ms
5,864 KB
testcase_50 AC 61 ms
5,868 KB
testcase_51 AC 64 ms
5,880 KB
testcase_52 AC 68 ms
5,908 KB
testcase_53 AC 63 ms
5,852 KB
testcase_54 AC 64 ms
5,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
 
char str[200005];

void func(int N, const char* S, int* R )
{
    int i = 0, j = 0;
    while (i < N) {
      while (i-j >= 0 && i+j < N && S[i-j] == S[i+j]) ++j;
      R[i] = j;
      int k = 1;
      while (i-k >= 0 && i+k < N && k+R[i-k] < j) R[i+k] = R[i-k], ++k;
      i += k; j -= k;
    }
    return;
}

int main(int argc, char* argv[])
{
    int N,K,Q;
    scanf("%d%d%d", &N, &K, &Q);
    scanf("%s", str);

    vector<char> ss;
    int i,k;
    for(k=0; k<3; k++) {
        for(i=0; i<N; i++) {
            ss.push_back(str[i]);
        }
    }
    ss.push_back('\0');

    vector<int> a(N*3);
    func(3*N, &ss[0], &a[0]);

    for(i=0; i<Q; i++) {
        ll p;
        scanf("%lld", &p); p--;
        int q=p%N;
        ll r=a[q+N]-1;
        if(r>=N) {
            r=MIN(p,(ll)N*K-1-p);
            printf("%lld\n", 2*r+1);
        }
        else {
            r=MIN(MIN(r,p),(ll)N*K-1-p);
            printf("%lld\n", 2*r+1);
        }
    }

    return 0;
}

0