# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666604 | mychecksedad | 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 <utility>
#include <bits/stdc++.h>
using namespace std;
/**
* use this function in encode when you want to send a certain signal
* (it might come out wrong, and the return value tells you which signal
* was actually sent)
*/
int send(int);
/**
* use this function in decode; it returns the next signal that was actually
* sent during the corresponding call of encode
*/
int receive();
/**
* implement these two functions yourself
*/
void encode(int N, int X){
if(X == 1){
send(0);
send(0);
send(0);
send(0);
}
if(X == 2){
send(0);
send(1);
send(1);
send(0);
}
if(X == 3){
send(1);
send(1);
send(1);
send(1);
}
}
pair<int, int> decode(int N) {
int a = 0, b = 0, x = 0;
int y[3] = {0, 6, 15};
for(int j = 0; j < 4; ++j) x += receive() * (1<<j);
map<int, bool> m;
auto corrupt = [&](int n){
m[n^1] = 1;
m[n^2] = 1;
m[n^4] = 1;
m[n^8] = 1;
m[n^5] = 1;
m[n^9] = 1;
m[n^10] = 1;
m[n] = 1;
};
for(int j = 0; j < 3; ++j){
corrupt(y[j]);
if(!m[x]){
m.clear();
continue;
}
m.clear();
for(int i = 0; i < 3; ++i){
if(i==j) continue;
corrupt(y[i]);
if(!m[x]){
m.clear();
continue;
}
m.clear();
if(ok){
a = j + 1;
b = i + 1;
return {a, b};
}
}
return {j + 1, j + 1};
}
return {1, 3};
}