Submission #687540

#TimeUsernameProblemLanguageResultExecution timeMemory
687540abcdehelloCombo (IOI18_combo)C++17
100 / 100
36 ms748 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

string guess_sequence(int n) {
	char pre=' ';
	string cur="";
	vector<char> other(0),buttons={'A','B','X','Y'};
	//find s[0] (2)
	int ab=press("AB"),ax=press("AX");
	if (ab&&ax) pre='A';
	else if (ab) pre='B';
	else if (ax) pre='X';
	else pre='Y';
	for (char ch:buttons){
		if (pre!=ch) other.push_back(ch);
	}
	cur+=pre;
	if (n==1) return cur;
	//find s[1..n-2] (n-2)
	for (int i=1;i<n-1;i++){
		string s1=cur+other[0],s2=cur+other[1];
		string s2a=s2+other[0],s2b=s2+other[1],s2c=s2+other[2];
		int res=press(s1+s2a+s2b+s2c);
		if (res==i+2) cur+=other[1];
		else if (res==i+1) cur+=other[0];
		else cur+=other[2];
	}
	//find s[n-1] (2)
	int cur1=press(cur+other[0]),cur2=press(cur+other[1]);
	if (cur1==n) return cur+other[0];
	else if (cur2==n) return cur+other[1];
	else return cur+other[2];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...