#include "bits/stdc++.h"
#include "combo.h"
using namespace std;
std::string guess_sequence(int n) {
string pb = "ABXY";
string possibilities = "";
string p = "";
string s = "";
if (press("AB") > 0){
if (press("A") == 1) s += 'A';
else s += 'B';
} else if (press("X") == 1) s += 'X';
else s+='Y';
p=s;
for (int i=0;i<pb.size();++i){
if (pb[i]==s[0]) continue;
possibilities+=pb[i];
}
// generate the string to ask until press(p) == n
// p and add to p the first character in possibilities that's not the prefix, then add the second one and append to the second one all other three that's not the prefix
int last_ans = 1;
while(true)
{
string toAdd = ""; // str to add to not modify p yet
toAdd+=possibilities[0]; // add first character
toAdd+=s[0]; // add prefix
toAdd+=possibilities[1]; // add second character
// to second character add all the possibilities
for(int i=0;i<possibilities.size();++i){
toAdd+=possibilities[i];
toAdd+=s[0];
}
// ask
int ans = press(p + toAdd);
// if we get 1, the sole character is good
if (ans-last_ans==1){
p+=possibilities[0];
} else if (ans-last_ans > 1){ // else if we get 2 the second character is good
p+=possibilities[1];
} else { // else it's the one we didn't ask of
p+=possibilities[2];
}
// update last ans;
last_ans = ans;
// if we reached last character
if (last_ans==n-1){
break;
}
}
// same as first to find first character
if (press("AB") - last_ans > 0){
if (press("A") - last_ans == 1) p += 'A';
else p += 'B';
} else if (press("X") - last_ans == 1) p += 'X';
else p+='Y';
s=p;
return s;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |