結果
問題 |
No.958 たぷりすたべる (回文)
|
ユーザー |
|
提出日時 | 2020-04-22 22:30:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 767 bytes |
コンパイル時間 | 685 ms |
コンパイル使用メモリ | 71,168 KB |
実行使用メモリ | 6,620 KB |
最終ジャッジ日時 | 2024-10-12 06:52:57 |
合計ジャッジ時間 | 10,924 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 52 WA * 1 |
コンパイルメッセージ
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=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; } } }