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 <bits/stdc++.h>
#include "combo.h"
using namespace std;
string res = "";
bool estSuivantAB;
string guess_sequence (int nbElements)
{
if (press("AB") > 0) {
res += press("A") ? 'A' : 'B';
}
else {
res += press("X") ? 'X' : 'Y';
}
if (nbElements == 1) {
return res;
}
if (res[0] == 'A' || res[0] == 'B') {
estSuivantAB = press(res+"X"+res+"Y") <= (int)res.size();
}
else {
estSuivantAB = press(res+"A"+res+"B") > (int)res.size();
}
while ((int)res.size() < nbElements) {
bool doitRecalculer = false;
char car1, car2;
if (estSuivantAB) {
car1 = 'A';
car2 = 'B';
}
else {
car1 = 'X';
car2 = 'Y';
}
if (res[0] == car1) {
res += car2;
doitRecalculer = true;
}
else if (res[0] == car2) {
res += car1;
doitRecalculer = true;
}
else {
string requete;
if (res[0] != 'A') {
requete += res+car1+'A';
}
if (res[0] != 'B') {
requete += res+car1+'B';
}
const int reponse = press(requete);
if (reponse > (int)res.size()) {
estSuivantAB = reponse == (int)res.size() + 2;
res += car1;
}
else {
res += car2;
doitRecalculer = true;
}
}
if (doitRecalculer) {
if (res[0] == 'A' || res[0] == 'B') {
estSuivantAB = press(res+"X"+res+"Y") <= (int)res.size();
}
else {
estSuivantAB = press(res+"A"+res+"B") > (int)res.size();
}
}
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |