Submission #541456

#TimeUsernameProblemLanguageResultExecution timeMemory
541456collodel콤보 (IOI18_combo)C++17
100 / 100
41 ms576 KiB
#include "combo.h"
#include <vector>
#include <iostream>
using namespace std;

std::string guess_sequence(int N) {
	string ans = "";
	
	// trova il primo carattere
	if(press(string("AB")) >= 1) {
		ans += (press(string("A")) == 1 ? "A" : "B");
	} else {
		ans += (press(string("X")) == 1 ? "X" : "Y");
	}

	vector<string> cs;
	if('X' != ans[0]) cs.push_back("X");
	if('A' != ans[0]) cs.push_back("A");
	if('B' != ans[0]) cs.push_back("B");
	if('Y' != ans[0]) cs.push_back("Y");

	while((int)ans.length() < N) {
		if((int)ans.length() == N-1) {
			// trova l'ultimo carattere
			if(press(ans + cs[0] + ans + cs[1]) == N) {
				ans += (press(ans + cs[0]) == N ? cs[0] : cs[1]);
			} else {
				ans += cs[2];
			}
			break;
		}
		string query = ans + cs[0] + ans + cs[1] + cs[0] + ans + cs[1] + cs[1] + ans + cs[1] + cs[2];
		int coins = press(query);
		if(coins == (int)ans.length()) ans += cs[2];
		else if(coins == (int)ans.length() + 1) ans += cs[0];
		else if(coins == (int)ans.length() + 2) ans += cs[1];
	}

	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...