-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patha1.cpp
66 lines (63 loc) · 1.06 KB
/
a1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
int T, N, K, A[500000], B[500000], R[500000];
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> T;
for(int tc = 1; tc <= T; tc++){
moo << "Case #" << tc << ": ";
eat >> N >> K;
for(int i = 0; i < N; i++){
eat >> A[i];
A[i]--;
}
for(int i = 0; i < N; i++){
eat >> B[i];
B[i]--;
}
if(N == 2){
bool eq = (A[0] == B[0]);
if((eq && K%2==0) || (!eq && K%2==1)){
moo << "YES" << endl;
}else{
moo << "NO" << endl;
}
continue;
}
bool eq = 1;
for(int i = 0; i < N; i++){
if(A[i] != B[i]){
eq = 0;
break;
}
}
if(K == 0){
if(eq) moo << "YES" << endl;
else moo << "NO" << endl;
continue;
}
for(int i = 0; i < N; i++){
R[A[i]] = i;
}
int start = R[B[0]];
bool ok = 1;
for(int i = 0; i < N; i++){
if(B[i] != A[(start+i)%N]){
ok = 0;
break;
}
}
if(K == 1 && eq){
ok = 0;
}
if(ok){
moo << "YES" << endl;
}else{
moo << "NO" << endl;
}
}
}