Submission #792535

#TimeUsernameProblemLanguageResultExecution timeMemory
792535Sohsoh84Combo (IOI18_combo)C++17
100 / 100
24 ms572 KiB
#include "combo.h"
#include <bits/stdc++.h>

using namespace std;

#define debug(x)		cerr << #x << ": " << x << endl;
#define sep			' '

int n;
string TC[4] = {"A", "B", "X", "Y"};

inline int tpress(string s) {
	//cerr << "press: " <<  s << endl;
	return press(s);
}

string guess_sequence(int N_) {
	int n = N_;
	string ans = TC[3];
	if (press(TC[0] + TC[1])) {
		if (press(TC[0])) ans = TC[0];
		else ans = TC[1];
	} else if (press(TC[2])) ans = TC[2];

	vector<string> C;
	for (int i = 0; i < 4; i++)
		if (TC[i] != ans)
			C.push_back(TC[i]);

	if (n == 1) return ans;

	for (int j = 0; j < n - 2; j++) {
		string tans = ans + C[0] + ans + C[1] + C[0] + ans + C[1] + C[1] + ans + C[1] + C[2];
		int score = tpress(tans);
		if (score == j + 1) ans += C[2];
		else if (score == j + 2) ans += C[0];
		else ans += C[1];
	}

	for (int i = 0; i < 2; i++)
		if (tpress(ans + C[i]) == n)
			return ans + C[i];

	return ans + C[2];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...