結果

問題 No.958 たぷりすたべる (回文)
ユーザー HIR180HIR180
提出日時 2019-12-21 00:11:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,893 bytes
コンパイル時間 1,848 ms
コンパイル使用メモリ 187,508 KB
実行使用メモリ 51,284 KB
最終ジャッジ日時 2023-09-25 05:42:48
合計ジャッジ時間 7,500 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
19,816 KB
testcase_01 AC 11 ms
19,924 KB
testcase_02 AC 11 ms
19,856 KB
testcase_03 AC 11 ms
19,860 KB
testcase_04 AC 11 ms
19,876 KB
testcase_05 AC 11 ms
19,972 KB
testcase_06 AC 11 ms
19,884 KB
testcase_07 AC 11 ms
19,924 KB
testcase_08 AC 11 ms
19,812 KB
testcase_09 AC 11 ms
19,860 KB
testcase_10 AC 11 ms
19,876 KB
testcase_11 AC 11 ms
19,848 KB
testcase_12 AC 11 ms
19,916 KB
testcase_13 AC 12 ms
19,880 KB
testcase_14 AC 11 ms
19,924 KB
testcase_15 AC 11 ms
19,960 KB
testcase_16 AC 11 ms
19,848 KB
testcase_17 AC 11 ms
19,860 KB
testcase_18 AC 11 ms
19,880 KB
testcase_19 AC 11 ms
19,860 KB
testcase_20 AC 12 ms
19,916 KB
testcase_21 AC 11 ms
19,816 KB
testcase_22 AC 12 ms
19,852 KB
testcase_23 AC 11 ms
19,872 KB
testcase_24 AC 11 ms
19,824 KB
testcase_25 AC 11 ms
19,856 KB
testcase_26 AC 11 ms
19,912 KB
testcase_27 AC 34 ms
19,916 KB
testcase_28 AC 34 ms
19,924 KB
testcase_29 AC 34 ms
19,876 KB
testcase_30 AC 33 ms
19,864 KB
testcase_31 AC 33 ms
19,912 KB
testcase_32 AC 33 ms
19,964 KB
testcase_33 AC 35 ms
19,964 KB
testcase_34 AC 34 ms
20,140 KB
testcase_35 AC 36 ms
19,860 KB
testcase_36 AC 34 ms
19,924 KB
testcase_37 AC 33 ms
19,904 KB
testcase_38 AC 35 ms
19,864 KB
testcase_39 AC 34 ms
19,968 KB
testcase_40 AC 34 ms
19,908 KB
testcase_41 AC 33 ms
19,928 KB
testcase_42 AC 36 ms
19,864 KB
testcase_43 AC 34 ms
19,928 KB
testcase_44 AC 36 ms
19,916 KB
testcase_45 AC 36 ms
19,916 KB
testcase_46 AC 35 ms
19,932 KB
testcase_47 AC 144 ms
41,584 KB
testcase_48 AC 161 ms
51,168 KB
testcase_49 AC 184 ms
51,284 KB
testcase_50 AC 165 ms
51,236 KB
testcase_51 AC 204 ms
51,236 KB
testcase_52 AC 219 ms
51,128 KB
testcase_53 AC 212 ms
51,188 KB
testcase_54 AC 207 ms
51,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
const ll mod = 1000000007;
int n,k,q;
ll h[1000005][2];
ll r[1000005][2];
ll num[1000005][2];
string ss,s;

int main(){
	cin >> n >> k >> q;
	cin >> ss;
	rep(i,5) s += ss;
	num[0][0] = num[0][1] = 1;
	rep(i,1000003){
		num[i+1][0] = num[i][0]*31LL%mod;
		num[i+1][1] = num[i][1]*37LL%mod;
	}
	rep(i,s.size()){
		rep(j,2){
			if(i) h[i][j] = h[i-1][j];
			h[i][j] += num[i][j]*(s[i]-'a'+1)%mod;
			if(h[i][j]>=mod) h[i][j]-=mod;
		}
	}
	for(int i=s.size()-1;i>=0;i--){
		rep(j,2){
			r[i][j] = r[i+1][j];
			r[i][j] += num[s.size()-1-i][j]*(s[i]-'a'+1)%mod;
			if(r[i][j]>=mod) r[i][j]-=mod;
		}
	}
	rep(i,q){
		ll a; scanf("%lld",&a);
		ll mn = min(a-1,1LL*k*n-a);
		int pos = (a-1)%(ss.size());
		int p = ss.size()*2+pos;
		int lb = 0, ub = n+1;
		while(ub-lb > 1){
			int mid = (lb+ub)/2;
			//[p-mid,p-1]
			//[p+1,p+mid]
			rep(j,2){
				//x^(p+1)
				ll vr = h[p+mid][j]-h[p][j];
				vr = vr*num[s.size()-p-1][j]%mod;
				//x^(s.size()-p)
				ll vl = r[p-mid][j]-r[p][j];
				vl = vl*num[p][j]%mod;
				if(vr < 0) vr+=mod;
				if(vl < 0) vl+=mod;
				if(vl != vr) goto fail;
			}
			lb = mid; continue;
			fail:; ub = mid;
		}
		if(lb != n){
			printf("%lld\n",min(1LL*lb,mn)*2LL+1);
		}
		else{
			printf("%lld\n",mn*2LL+1);
		}
	}
}
0