#include <bits/stdc++.h>
#include "communication.h"
using namespace std;
void encode(int N, int X) {
assert(N == 3);
bool lo = (X >> 0) & 1;
bool hi = (X >> 1) & 3;
int sent = 0;
do sent++; while (send(lo) != lo) ;
while (sent++ < 4 && send(lo) == lo) ;
while (sent++ < 4) send(hi);
}
constexpr int LEN = 4;
pair<int, int> starting_guesses(vector<int> packet) {
if (packet[0] == packet[1] && packet[1] == packet[2])
return {packet[1], packet[1] + 2};
return {packet[0] + 2 * packet[2], packet[1] + 2 * packet[3]};
}
pair<int, int> decode(int N) {
vector<int> message(LEN);
for (auto &x: message) x = receive();
auto [guess_1, guess_2] = starting_guesses(vector(message.end() - 4, message.end()));
return {min(N, guess_1), min(N, guess_2)};
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
412 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
584 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |