# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
723124 | sunnat | Flight to the Ford (BOI22_communication) | C++17 | 0 ms | 0 KiB |
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>
#include <algorithm>
using namespace std;
//
// --- Sample implementation for the task communication ---
//
// To compile this program with the sample grader, place:
// communication.h communication_sample.cpp sample_grader.cpp
// in a single folder, then open the terminal in this directory (right-click onto an empty spot in the directory,
// left click on "Open in terminal") and enter e.g.:
// g++ -std=c++17 communication_sample.cpp sample_grader.cpp
// in this folder. This will create a file a.out in the current directory which you can execute from the terminal
// as ./a.out
// See task statement or sample_grader.cpp for the input specification
//
void encode(int N, int X) {
while(N > 0){
N /= 2;
send(x%2);
send(x%2);
send(x%2);
x /= 2;
}
}
vector<int> a, res;
void brute_force(int x, int i, bool f){
if(i*3 == a.size()){
res.push_back(x);
return;
}int j = i*3;
if(f){
if(a[j] != a[j+1] && a[j] != a[j+2])
return;
brute_force(x * 2 + a[i*3], i+1, a[i*3] == a[i*3+2]);
return;
}
if(a[j] == a[j+1])
brute_force(x * 2 + a[j], i+1, a[j] == a[j+2]);
else if(a[j+1] == a[j+2])
brute_force(x * 2 + a[j+1], i+1, true);
else{
brute_force(x*2+a[j], i+1, a[j] == a[j+2]);
brute_force(x*2+a[j+1], i+1, a[j+1] == a[j+2]);
}
}
std::pair<int, int> decode(int N) {
a.clear();
while(N > 0){
N /= 2;
a.push_back(receive());
a.push_back(receive());
a.push_back(receive());
}
res.clear();
brute_force(0, 0, 0);
sort(res.begin(), res.end());
if(res[0] == 0) res.erase(res.begin());
if(res.size() == 1) return {res[0], res[0]};
int i = rnd() % res.size(), j;
while((j = rnd() % res.size()) != i);
return {res[i], res[j]};
}