Submission #82846

#TimeUsernameProblemLanguageResultExecution timeMemory
82846leejseoCombo (IOI18_combo)C++11
100 / 100
56 ms544 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

int first = -1;
char X[] = {'A', 'B', 'X', 'Y'};
inline char getChar(int x){
	if (x < first) return X[x];
	return X[x+1];
}

string guess_sequence(int N) {
  string p = "";
	int v1 = press("AB");
	int v2 = press("AX");
	// Determine first letter;
	if (v1 >= 1 && v2 >= 1){
		p += "A";
		first = 0;
	}
	else{
		if (v1 >= 1){
			p += "B";
			first = 1;
		}
		else{
			if (v2 >= 1){
				p += "X";
				first = 2;
			}
			else{
				p += "Y";
				first = 3;
			}
		}
	}
	if (N == 1) return p;
	// Determine 2nd, 3rd, ..., N-1th letter
	for (int i=0; i<N-2; i++){
		string to_guess = "";
		for (int j=0; j<3; j++){
			to_guess += p;
			to_guess += getChar(0);
			to_guess += getChar(j);		
		}
		to_guess += p;
		to_guess += getChar(1);
		int res = press(to_guess);
		if (res == i+2) p += getChar(1);
		else{
			if (res == i+3) p += getChar(0);
			else p += getChar(2);
		}
	}
	// Determine last letter
	if (press(p+getChar(0))==N) return p + getChar(0);
	if (press(p+getChar(1))==N) return p + getChar(1);
	return p + getChar(2);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...