結果
| 問題 |
No.958 たぷりすたべる (回文)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-22 22:32:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 396 ms / 2,000 ms |
| コード長 | 774 bytes |
| コンパイル時間 | 588 ms |
| コンパイル使用メモリ | 72,108 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-12 06:56:19 |
| 合計ジャッジ時間 | 9,120 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 53 |
コンパイルメッセージ
main.cpp:22:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
22 | main()
| ^~~~
ソースコード
#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;
}
}
}