結果
問題 |
No.2254 Reverse Only
|
ユーザー |
|
提出日時 | 2023-03-24 22:07:56 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 153 ms / 2,000 ms |
コード長 | 960 bytes |
コンパイル時間 | 1,560 ms |
コンパイル使用メモリ | 94,064 KB |
実行使用メモリ | 11,836 KB |
最終ジャッジ日時 | 2024-09-18 17:08:42 |
合計ジャッジ時間 | 7,125 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<cassert> #include<atcoder/string> using namespace std; int N,K; int main() { cin>>N>>K; vector<int>A(N),B(N); for(int i=0;i<N;i++)cin>>A[i]; for(int i=0;i<N;i++)cin>>B[i]; if(A==B) { cout<<"Yes"<<endl; return 0; } if(K>N) { cout<<"No"<<endl; return 0; } if(K==2||K+2<=N) { sort(A.begin(),A.end()); sort(B.begin(),B.end()); if(A==B)cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; } if(K==N) { reverse(A.begin(),A.end()); if(A==B)cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; } assert(K+1==N); vector<int>L=B,R=B; L.pop_back(); R.pop_back(); reverse(R.begin(),R.end()); for(int t=0;t<2;t++)for(int a:A) { L.push_back(a); R.push_back(a); } L=atcoder::z_algorithm(L); R=atcoder::z_algorithm(R); for(int i=0;i<N;i++)if(A[i]==B[N-1]) { if(max(L[N+i],R[N+i])>=N-1) { cout<<"Yes"<<endl; return 0; } } cout<<"No"<<endl; }