結果

問題 No.958 たぷりすたべる (回文)
ユーザー tarattata1tarattata1
提出日時 2019-12-21 00:35:07
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 556 ms
コンパイル使用メモリ 75,168 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-18 05:19:30
合計ジャッジ時間 3,908 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 53
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:44:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |     scanf("%d%d%d", &N, &K, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |     scanf("%s", str);
      |     ~~~~~^~~~~~~~~~~
main.cpp:61:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   61 |         scanf("%lld", &p); p--;
      |         ~~~~~^~~~~~~~~~~~

ソースコード

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