結果

問題 No.958 たぷりすたべる (回文)
ユーザー kotatsugamekotatsugame
提出日時 2020-04-22 22:32:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 73,168 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 11:16:58
合計ジャッジ時間 9,405 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 143 ms
6,944 KB
testcase_28 AC 157 ms
6,940 KB
testcase_29 AC 153 ms
6,944 KB
testcase_30 AC 144 ms
6,944 KB
testcase_31 AC 147 ms
6,944 KB
testcase_32 AC 146 ms
6,944 KB
testcase_33 AC 153 ms
6,948 KB
testcase_34 AC 164 ms
6,940 KB
testcase_35 AC 156 ms
6,940 KB
testcase_36 AC 144 ms
6,944 KB
testcase_37 AC 142 ms
6,940 KB
testcase_38 AC 143 ms
6,944 KB
testcase_39 AC 151 ms
6,940 KB
testcase_40 AC 144 ms
6,944 KB
testcase_41 AC 143 ms
6,944 KB
testcase_42 AC 147 ms
6,940 KB
testcase_43 AC 145 ms
6,944 KB
testcase_44 AC 154 ms
6,940 KB
testcase_45 AC 152 ms
6,940 KB
testcase_46 AC 139 ms
6,944 KB
testcase_47 AC 354 ms
6,940 KB
testcase_48 AC 369 ms
6,940 KB
testcase_49 AC 358 ms
6,940 KB
testcase_50 AC 347 ms
6,940 KB
testcase_51 AC 354 ms
6,944 KB
testcase_52 AC 367 ms
6,940 KB
testcase_53 AC 372 ms
6,944 KB
testcase_54 AC 359 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   22 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
#include<vector>
#include<string>
vector<int>manacher(const string&s)
{
	vector<int>ret(s.size());
	int i=0,j=0;
	while(i<s.size())
	{
		while(i-j>=0&&i+j<s.size()&&s[i-j]==s[i+j])j++;
		ret[i]=j;
		int k=1;
		while(i-k>=0&&i+k<s.size()&&k+ret[i-k]<j)ret[i+k]=ret[i-k],k++;
		i+=k;j-=k;
	}
	return ret;
}
long N;
int K,Q;
string s,t;
main()
{
	cin>>N>>K>>Q>>s;
	if(K<=2)
	{
		t=K==2?s+s:s;
		vector<int>ret=manacher(t);
		for(;Q--;)
		{
			int a;cin>>a;
			cout<<ret[a-1]*2-1<<endl;
		}
		return 0;
	}
	t=s+s+s;
	vector<int>ret=manacher(t);
	for(;Q--;)
	{
		long A;cin>>A;A--;
		long X=ret[A%N+N];
		if(X==A%N+N+1||A%N+N+X==3*N)
		{
			cout<<min(A+1,N*K-A)*2-1<<endl;
		}
		else
		{
			cout<<min(X,min(A+1,N*K-A))*2-1<<endl;
		}
	}
}
0