forked from JohnJordan0098/Data-Structures-Algos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAFLIP.cpp
104 lines (101 loc) · 2.21 KB
/
AFLIP.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// https://www.codechef.com/AUG221D/problems/AFLIP
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
vector<int> ae, ao, be, bo;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if ((i + j) % 2 == 0)
{
int x;
cin >> x;
ae.push_back(x);
}
else
{
int x;
cin >> x;
ao.push_back(x);
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if ((i + j) % 2 == 0)
{
int x;
cin >> x;
be.push_back(x);
}
else
{
int x;
cin >> x;
bo.push_back(x);
}
}
}
int s;
if (m == 1 || n == 1)
{
if (ae == be)
{
if (ao == bo)
{
s = 1;
}
else
{
s = 0;
}
}
else
{
s = 0;
}
}
else
{
sort(ae.begin(), ae.end());
sort(ao.begin(), ao.end());
sort(be.begin(), be.end());
sort(bo.begin(), bo.end());
for (int i = 0; i < (n * m) / 2; i++)
{
if (ae[i] != be[i])
{
s = 0;
break;
}
// else if (ae[i]!=be[i])
// {
// s=0;
// break;
// }
else
{
s = 1;
}
}
}
if (s == 1)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
}
}