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 <string>
#include <vector>
#include <assert.h>
using namespace std;
int press(string p);
string guess_sequence(int n) {
string ans;
if (press("AB") > 0) {
if (press("A")) ans = "A";
else ans = "B";
}
else {
if (press("X")) ans = "X";
else ans = "Y";
}
assert((int)ans.size() == 1);
if (n == 1) return ans;
vector<char> v;
if (ans != "A") v.push_back('A');
if (ans != "B") v.push_back('B');
if (ans != "X") v.push_back('X');
if (ans != "Y") v.push_back('Y');
assert(v.size() == 3);
for (int i = 1; i < n - 1; ++i) {
string s = ans + v[0] + v[0] + ans + v[0] + v[1] + ans + v[0] + v[2] + ans + v[1];
assert((int)s.size() <= 4 * n);
int x = press(s);
if (x == i) ans += v[2];
else if (x == i + 1) ans += v[1];
else if (x == i + 2) ans += v[0];
else assert(0);
}
assert((int)ans.size() == n - 1);
if (press(ans + v[0]) == n) ans += v[0];
else if (press(ans + v[1]) == n) ans += v[1];
else ans += v[2];
assert((int)ans.size() == n);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |