This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "communication.h"
#include <vector>
constexpr int B = 30;
int send_trit(int T) {
int position = 0;
int depth = 0;
while (depth < 2) {
int intent = 0;
if (position % 3 != (T + 2) % 3) intent = 1;
if (send(intent) == 0) ++position;
else ++depth;
//if (position == 4) return 2;
}
return (position + 1) % 3;
}
void encode(int N, int X) {
--X;
if (N > 3) return;
send_trit(X);
}
int receive_trit() {
int position = 0;
int depth = 0;
while (depth < 2) {
if (receive() == 0) ++position;
else ++depth;
//if (position == 4) return 2;
}
return (position + 1) % 3;
}
std::pair<int, int> decode(int N) {
int X = receive_trit();
return { (X + 1) % 3 + 1, (X + 2) % 3 + 1 };
}
// g++ -std=c++17 sample_grader.cpp communication.cpp
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |