This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#include <string>
using namespace std;
int press(string p);
char binary_guess(string prefix, string cd)
{
int pn = prefix.length();
if (press(prefix + cd[0] + prefix + cd[1]) > pn)
{
if (press(prefix + cd[0]) > pn)
return cd[0];
return cd[1];
}
if (press(prefix + cd[2]) > pn)
return cd[2];
return cd[3];
}
string guess_sequence(int N)
{
string prefix;
string buttons = "ABXY";
prefix += binary_guess("", buttons);
buttons.erase(buttons.begin() + buttons.find(prefix[0]));
if (N == 1)
return prefix;
int pn;
while ((pn = prefix.length()) < N - 1)
{
string query_string;
query_string += prefix + buttons[0];
for (int i=0; i<3; i++)
query_string += prefix + buttons[1] + buttons[i];
int n = press(query_string);
if (n == pn + 1)
prefix += buttons[0];
else if (n == pn + 2)
prefix += buttons[1];
else
prefix += buttons[2];
}
prefix += binary_guess(prefix, buttons);
return prefix;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |