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<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include "combo.h"
using namespace std;
string guess_sequence(int N) ///Guess the combo sequence
{
string p="";
string Q="AB";
char letter[4];
char l[4]={'A','B','X','Y'};
int answer=press(Q);
if(answer>=1){ //We find the first letter in two queries
if(press("A"))
p+='A';
else
p+='B';
}
else{
if(press("X"))
p+='X';
else
p+='Y';
}
int j=0;
for(int i=0;i<4;i++){ //Ans we eliminate it from possible letters
if(p[0]!=l[i]){
letter[j++]=l[i];
}
}
for(int i=2;i<N;i++){ //For each letter we guess it making a query with 3 different return values (one for each letter)
Q=p+letter[0]+p+letter[1]+letter[0]+p+letter[1]+letter[1]+p+letter[1]+letter[2];
answer=press(Q);
if(answer==i-1){
p+=letter[2];
}
else if(answer==i){
p+=letter[0];
}
else if(answer==i+1){
p+=letter[1];
}
}
if(N>1){ //We guess the last letter with two queries
if(press(p+letter[0])==N){
p+=letter[0];
}
else if(press(p+letter[1])==N){
p+=letter[1];
}
else{
p+=letter[2];
}
}
return p;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |