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;
const int NB_MAX_CARACTERES = 2000;
string res = "";
vector<char> possibles[NB_MAX_CARACTERES];
string guess_sequence (int nbCaracteres)
{
srand(12);
if (press("AB") > 0) {
res += press("A") ? 'A' : 'B';
}
else {
res += press("X") ? 'X' : 'Y';
}
if (nbCaracteres == 1) {
return res;
}
possibles[0].push_back(res[0]);
for (int iCaractere=1; iCaractere<nbCaracteres; iCaractere++) {
for (char c : "ABXY") {
if (c != res[0] && c != 0) {
possibles[iCaractere].push_back(c);
}
}
}
while ((int)res.size() < nbCaracteres) {
vector<string> mots;
mots.push_back(res);
while ((int)mots[0].size() < nbCaracteres) {
const int iCaractere = mots[0].size();
random_shuffle(possibles[iCaractere].begin(), possibles[iCaractere].end());
vector<string> nouveauxMots;
for (const string &mot : mots) {
nouveauxMots.push_back(mot + possibles[iCaractere][0]);
if (possibles[iCaractere].size() == 3) {
nouveauxMots.push_back(mot + possibles[iCaractere][1]);
}
}
if ((int)nouveauxMots[0].size() * (int)nouveauxMots.size() <= 4*nbCaracteres) {
mots = nouveauxMots;
}
else {
break;
}
}
string requete;
for (string mot : mots) {
requete += mot;
}
const int reponse = press(requete);
// Caractères valides
bool estValide = true;
for (int iCaractere=res.size(); iCaractere<reponse; iCaractere++) {
if (possibles[iCaractere].size() >= 2) {
possibles[iCaractere].pop_back();
}
if (possibles[iCaractere].size() == 1 && estValide) {
res += possibles[iCaractere][0];
}
else {
estValide = false;
}
}
// Dernier caractère, si il est invalide
if (reponse < nbCaracteres && (int)mots[0].size() > reponse) {
while (possibles[reponse].size() > 1) {
possibles[reponse].erase(possibles[reponse].begin());
}
}
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |