#include <bits/stdc++.h>
#include <communication.h>
using namespace std;
vector <string> arr = {
"1010",
"1001",
"1000",
"0101",
"0100",
"0010",
"0001",
"0000"
};
string pp (string a, string b) {
string ret;
for (int i = 0; i < 4; i++) {
if (a[i] == b[i]) ret += '0';
else ret += '1';
}
return ret;
}
void encode (int n, int x) {
if (x == 1) {
send(0); send(0); send(0); send(0);
} else if (x == 2) {
send(0); send(1); send(1); send(0);
} else {
send(1); send(0); send(0); send(1);
}
}
pair <int, int> decode (int n) {
string a = "0000", b = "0110", c = "1001";
map <string, vector <int>> x;
for (auto i : arr) x[pp(a, i)].push_back(1);
for (auto i : arr) x[pp(b, i)].push_back(2);
for (auto i : arr) x[pp(c, i)].push_back(3);
string s; for (int i = 0; i < 4; i++) s += (char)(receive() + '0');
if (x[s].size() == 1) {
return {x[s].front(), x[s].front()};
} else {
return {x[s].front(), x[s].back()};
}
}
/*
0000
1100
0010
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2744 KB |
Output is correct |
2 |
Correct |
5 ms |
2752 KB |
Output is correct |
3 |
Correct |
6 ms |
2940 KB |
Output is correct |
4 |
Correct |
4 ms |
3064 KB |
Output is correct |
5 |
Correct |
5 ms |
2760 KB |
Output is correct |
6 |
Correct |
14 ms |
3048 KB |
Output is correct |
7 |
Correct |
23 ms |
2784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
332 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |