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 <bits/stdc++.h>
using namespace std;
char btns[] = {'A', 'B', 'X', 'Y'};
string guess(string known, int n) {
// cout << known << " " << n << '\n';
if (known.length() == n)
return known;
int x;
int len = known.length();
if (!len) {
x = press("AB");
if (x == 2) {
return guess("AB", n);
} else if (x == 1) {
x = press("A");
if (x == 1) {
return guess("A", n);
} else {
return guess("B", n);
}
}
x = press("X");
if (x == 1) {
return guess("X", n);
} else {
return guess("Y", n);
}
// Unreachable
exit(-1);
}
if (len == n - 1) {
x = press(known + "A" + known + "B");
if (x == n) {
x = press(known + "A");
if (x == n) {
return known + "A";
} else {
return known + "B";
}
}
x = press("X");
if (x == 1) {
return known + "X";
} else {
return known + "Y";
}
}
auto first = known[0];
char candidates[3];
{
int ci = 0;
for (auto c : btns) {
if (first == c)
continue;
candidates[ci++] = c;
}
}
string q = "";
q += known;
q += candidates[0];
for (auto j = 0; j < 3; ++j) {
auto candidate2 = candidates[j];
q += known;
q += candidates[1];
q += candidate2;
}
x = press(q);
if (x == len) {
return guess(known + candidates[2], n);
} else if (x == len + 1) {
return guess(known + candidates[0], n);
} else {
return guess(known + candidates[1], n);
}
}
string guess_sequence(int N) { return guess("", N); }
Compilation message (stderr)
combo.cpp: In function 'std::string guess(std::string, int)':
combo.cpp:10:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
10 | if (known.length() == n)
| ~~~~~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |