Submission #704255

#TimeUsernameProblemLanguageResultExecution timeMemory
704255TranGiaHuy1508Flight to the Ford (BOI22_communication)C++17
15 / 100
37 ms1820 KiB
#include <bits/stdc++.h>
using namespace std;

#include "communication.h"

void encode(int N, int X){
	// Solve for N <= 3
	if (X == 1){
		int c1 = send(0);
		if (c1 == 0){
			send(0);
			// message = 00 / 01
		}
		else{
			send(1);
			send(0);
			// message = 110 / 111
		}
	}
	else if (X == 2){
		int c1 = send(1);
		if (c1 == 0){
			send(0);
			// message = 00
		}
		else{
			int c2 = send(0);
			if (c2 == 0){
				send(0);
				// message = 100 / 101
			}
			else{
				send(0);
				// message = 110
			}
		}
	}
	else{
		int c1 = send(1);
		if (c1 == 0){
			send(1);
			// message = 01
		}
		else{
			int c2 = send(0);
			if (c2 == 0){
				send(0);
				// message = 100 / 101
			}
			else{
				send(1);
				// message = 111
			}
		}
	}
}

pair<int, int> decode(int N){
	int c1 = receive();
	if (c1 == 0){
		int c2 = receive();
		if (c2 == 0) return {1, 2};
		else return {1, 3};
	}
	else{
		int c2 = receive();
		int c3 = receive();

		if (c2 == 0) return {2, 3};
		if (c3 == 0) return {1, 2};
		else return {1, 3};
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...