# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941324 | william950615 | 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<bits/stdc++.h>
//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) {
auto send_bit = [&](bool x, bool y) {
send( x );
send( x );
send( y );
send( x );
send( y );
send( y );
};
send_bit( (X>>1)&1, X&1 );
}
std::pair<int, int> decode(int N) {
int ans[2];
for( auto &i : ans ) i = -1;
auto receive_bit = [&](int a, int b) {
int bi[6];
for( int i = 0; i < 6; ++i )
bi[i] = receive();
if( bi[0] == bi[1] )
ans[a]=bi[0];
if( bi[4] == bi[5] )
ans[b]=bi[5];
if( bi[1] != bi[3] )
ans[b]=bi[2];
if( bi[2] != bi[4] )
ans[a]=bi[3];
};
receive_bit( 1, 0 );
// assert( ans[1] != -1 || ans[0] != -1 );
// cout << ans[0] << ' ' << ans[1] << '\n';
if( ans[1] != -1 ) {
if( ans[1] == 0 )
return {1,2};
else
return {2,3};
}
if( ans[0] != -1 ) {
if( ans[0] == 0 )
return {2,3};
else
return {1,3};
}
assert( false);
}