結果

問題 No.958 たぷりすたべる (回文)
ユーザー tarattata1tarattata1
提出日時 2019-12-21 00:33:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,506 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 77,960 KB
実行使用メモリ 6,012 KB
最終ジャッジ日時 2023-09-25 06:14:49
合計ジャッジ時間 4,544 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 21 ms
4,376 KB
testcase_28 AC 20 ms
4,376 KB
testcase_29 AC 21 ms
4,376 KB
testcase_30 AC 21 ms
4,376 KB
testcase_31 AC 20 ms
4,376 KB
testcase_32 AC 20 ms
4,376 KB
testcase_33 AC 20 ms
4,376 KB
testcase_34 AC 20 ms
4,376 KB
testcase_35 AC 20 ms
4,380 KB
testcase_36 AC 20 ms
4,376 KB
testcase_37 AC 21 ms
4,376 KB
testcase_38 AC 21 ms
4,376 KB
testcase_39 AC 21 ms
4,384 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
権限があれば一括ダウンロードができます

ソースコード

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++) {
        int p;
        scanf("%d", &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