#include "combo.h"
using namespace std;
string guess_sequence(int N) {
string path = "";
{
int res = press ("AB");
if (res == 2) {
path = "AB";
} else if (res == 1) {
if (press ("A") == 1)
path = "A";
else
path = "B";
} else {
if (press ("X") == 1)
path = "X";
else
path = "Y";
}
}
string chars;
if (path[0] == 'A')
chars = "BXY";
else if (path[0] == 'B')
chars = "AXY";
else if (path[0] == 'X')
chars = "ABY";
else
chars = "ABX";
while (path.size() + 2 <= N) {
string to_ask = (
path + chars[0] +
path + chars[1] + chars[0] +
path + chars[1] + chars[1] +
path + chars[1] + chars[2]
);
int res = press (to_ask);
if (res == path.size())
path += chars[2];
else if (res == path.size() + 1)
path += chars[0];
else if (res == path.size() + 2)
path += chars[1];
else
exit (2);
}
if (path.size() == N)
return path;
if (path.size() + 1 == N) {
if (press (path + chars[0]) == N)
return path + chars[0];
else if (press (path + chars[1]) == N)
return path + chars[1];
else
return path + chars[2];
}
exit (1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |