Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2022 /round1 /consecutive_cuts_ch1.cpp
wjomlex's picture
2022 Problems
f7ba5f2 verified
raw
history blame
1.05 kB
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
const int LIM = 500000;
int N, K;
vector<int> A, B;
string solve() {
bool is_equal = A == B;
// Check special cases.
if (K == 0) {
return is_equal ? "YES" : "NO";
}
if (K == 1 && is_equal) {
return "NO";
}
if (N == 2) {
if (is_equal) {
return K % 2 == 0 ? "YES" : "NO";
}
return K % 2 == 0 ? "NO" : "YES";
}
// Check array is rotated.
int num_out_of_order = 0;
unordered_map<int, int> pos;
for (int i = 0; i < N; i++) {
pos[A[i]] = i;
}
for (int i = 0; i < N; i++) {
if (pos[B[i]] > pos[B[(i + 1) % N]]) {
num_out_of_order++;
}
}
return num_out_of_order == 1 ? "YES" : "NO";
}
int main() {
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
cin >> N >> K;
A.resize(N);
B.resize(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
cin >> B[i];
}
cout << "Case #" << t << ": " << solve() << endl;
}
return 0;
}