結果
| 問題 |
No.2254 Reverse Only
|
| コンテスト | |
| ユーザー |
noya2
|
| 提出日時 | 2023-03-13 15:03:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 163 ms / 2,000 ms |
| コード長 | 1,115 bytes |
| コンパイル時間 | 2,704 ms |
| コンパイル使用メモリ | 216,940 KB |
| 最終ジャッジ日時 | 2025-02-11 10:52:51 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/string>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
void yes(){ printf("Yes\n"); }
void no(){ printf("No\n"); }
int main(){
int n, k; cin >> n >> k;
vector<int> a(n), b(n);
rep(i,n) cin >> a[i];
rep(j,n) cin >> b[j];
if (a == b){
yes();
}
else if (k > n){
no();
}
else if (k == n){
reverse(all(b));
a == b ? yes() : no();
}
else if (k == n-1){
vector<int> c(3*n), d(3*n);
rep(i,n){
c[i] = a[i], d[i] = a[i];
c[n+i] = b[i], d[n+i] = b[n-1-i];
c[2*n+i] = b[i], d[2*n+i] = b[n-1-i];
}
auto zc = atcoder::z_algorithm(c);
auto zd = atcoder::z_algorithm(d);
bool ans = false;
rep(i,n){
if (zc[n+i] >= n) ans = true;
if (zd[n+i] >= n) ans = true;
}
ans ? yes() : no();
}
else {
vector<int> sa = a; sort(all(sa));
vector<int> sb = b; sort(all(sb));
sa == sb ? yes(): no();
}
}
noya2