Submission #75228

#TimeUsernameProblemLanguageResultExecution timeMemory
75228tincamateiCombo (IOI18_combo)C++14
100 / 100
58 ms592 KiB
#include <bits/stdc++.h>
#include "combo.h"

using namespace std;

std::string guess_sequence(int N) {
 	int AB = press("AB"), AX = press("AX");
	std::string rez;
	std::string buttons = "ABXY", remButtons;
	std::string suff[4];

	if(AB && AX)
		rez.push_back('A');
	else if(AB && !AX)
		rez.push_back('B');
  else if(!AB && AX)
		rez.push_back('X');
	else
		rez.push_back('Y');
	
	for(int i = 0; i < 4; ++i)
		if(buttons[i] != rez[0])
			remButtons.push_back(buttons[i]);
	
	suff[0] = string(1,remButtons[0]) + remButtons[0];
	suff[1] = string(1,remButtons[0]) + remButtons[1];
	suff[2] = string(1,remButtons[0]) + remButtons[2];
	suff[3] = string(1,remButtons[1]);

	for(int i = 2; i <= N - 1; ++i) {
		std::string query;
		for(int i = 0; i < 4; ++i)
			query = query + rez + suff[i];

		int coins = press(query);
		if(coins == i - 1)
			rez.push_back(remButtons[2]);
		else if(coins == i)
			rez.push_back(remButtons[1]);
		else
			rez.push_back(remButtons[0]);
		
	}
	if(N > 1) {	
		AB = (press(rez + "A" + rez + "B") == N), AX = (press(rez + "A" + rez + "X") == N);
		if(AB && AX)
			rez.push_back('A');
		else if(AB && !AX)
			rez.push_back('B');
  	else if(!AB && AX)
			rez.push_back('X');
		else
			rez.push_back('Y');
	}
	return rez;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...