Submission #941316

# Submission time Handle Problem Language Result Execution time Memory
941316 2024-03-08T13:31:29 Z william950615 Flight to the Ford (BOI22_communication) C++17
0 / 100
15 ms 352 KB
#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};
	}

}

Compilation message

communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Security violation!
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 352 KB Security violation!
2 Halted 0 ms 0 KB -