답안 #941324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941324 2024-03-08T13:38:22 Z william950615 Flight to the Ford (BOI22_communication) C++17
컴파일 오류
0 ms 0 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};
	}
	assert( false); 
}

Compilation message

communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:61:2: error: 'assert' was not declared in this scope
   61 |  assert( false);
      |  ^~~~~~
communication.cpp:2:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    1 | #include"communication.h"
  +++ |+#include <cassert>
    2 | //#include<bits/stdc++.h>
communication.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^