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 "combo.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int mpress(string s) {
int g = press(s);
// cout << "Press " << s << " = " << g << endl;
return g;
}
std::string guess_sequence(int N) {
vector<char> c = {'A', 'B', 'X', 'Y'};
string f = "";
if(press("XY") > 0) {
f = mpress("X") > 0 ? "X" : "Y";
} else {
f = mpress("A") > 0 ? "A" : "B";
}
if(N == 1) {
return f;
}
c.erase(find(c.begin(), c.end(), f[0]));
// A. -> 1
// BA. -> 2
// BB. -> 2
// BC. -> 2
// B. -> 1
// CA -> 2
// CB -> 2
for(int i = 1; i < N - 1; ++i) {
string s = "";
s += f + c[0];
s += f + c[1] + c[0];
s += f + c[1] + c[1];
s += f + c[1] + c[2];
int g = mpress(s) - i;
if(g == 0) f += c[2];
if(g == 1) f += c[0];
if(g == 2) f += c[1];
// cout << "f = " << f << endl;
}
// 2 + (N - 2) calls done
if(mpress(f + c[0]) == N) return f + c[0];
if(mpress(f + c[1]) == N) return f + c[1];
return f + c[2];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |