#include "communication.h"
void encode(int N, int X) {
if (X == 1) {
send(0);
send(0);
} else if (X == 2) {
send(0);
send(1);
} else if (X == 3) {
send(1);
send(0);
}
send(0);
}
std::pair<int, int> decode(int N) {
int signals[4];
for (int i = 0; i < 4; ++i) {
signals[i] = receive();
}
std::pair<int, int> result = {0, 0};
bool foundMessage1 = false;
bool foundMessage2 = false;
bool foundMessage3 = false;
if (signals[0] == 0 && signals[1] == 0) {
foundMessage1 = true;
}
if (signals[0] == 0 && signals[1] == 1) {
foundMessage2 = true;
}
if (signals[0] == 1 && signals[1] == 0) {
foundMessage3 = true;
}
if (foundMessage1) {
result.first = 1;
result.second = 1;
}
if (foundMessage2) {
result.first = 2;
result.second = 2;
}
if (foundMessage3) {
if (result.first == 0) {
result.first = 3;
result.second = 3;
} else {
result.second = 3;
}
}
if (result.first == 0) {
return {1, 1};
}
return result;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
352 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |