-
Notifications
You must be signed in to change notification settings - Fork 3
/
uxuhulvoting.cpp
59 lines (54 loc) · 1.16 KB
/
uxuhulvoting.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
#include <bits/stdc++.h>
using namespace std;
#define hset unordered_set
int M;
// States, Grid
vector<vector<int>> S, G;
int best(vector<int> &P, hset<int> &states) {
vector<tuple<int, int>> A(8);
for (int i = 0; i < 8; ++i) {
A[i] = make_tuple(P[i], i);
}
sort(A.begin(), A.end());
for (int i = 0; i < 8; ++i) {
int p, k;
tie(p, k) = A[i];
if (states.find(k) != states.end()) return k;
}
return 0;
}
int solve(int i, int state) {
if (S[i][state] != -1) return S[i][state];
int res;
hset<int> states;
for (int k = 0; k < 3; ++k) {
int s2 = state;
s2 ^= (1 << k);
if (i + 1 == M) states.insert(s2);
else states.insert(solve(i + 1, s2));
}
res = best(G[i], states);
S[i][state] = res;
return res;
}
int main() {
int T;
cin >> T;
while (T--) {
cin >> M;
G = vector<vector<int>>(M, vector<int>(8, - 1));
S = G;
for (auto &row : G) {
for (auto &i : row) cin >> i;
}
int res = solve(0, 0);
string output;
for (int i = 0; i < 3; ++i) {
if (res & 1) output = 'Y' + output;
else output = 'N' + output;
res >>= 1;
}
cout << output << endl;
}
return 0;
}