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;
char chr[3];
map<string, int> mp;
int ask(string str){
if(mp.find(str) == mp.end()) mp[str] = press(str);
return mp[str];
}
string guess_sequence(int n){
string s;
if(ask("AB")){
if(ask("A")){
s = "A";
chr[0] = 'B', chr[1] = 'X', chr[2] = 'Y';
}
else{
s = "B";
chr[0] = 'A', chr[1] = 'X', chr[2] = 'Y';
}
}
else{
if(ask("X")){
s = "X";
chr[0] = 'A', chr[1] = 'B', chr[2] = 'Y';
}
else{
s = "Y";
chr[0] = 'A', chr[1] = 'B', chr[2] = 'X';
}
}
while(s.size() < n){
if(n - s.size() >= 3){
string nextstr = s + chr[0] + chr[0] + chr[0] + s + chr[0] + chr[1] + chr[0] + s + chr[0] + chr[2] + chr[0] + s + chr[1] + chr[0] + chr[0];
if(ask(nextstr) - s.size() == 0) s += chr[2];
else if(ask(nextstr) - s.size() == 1){
if(ask(s + chr[1] + chr[1]) - s.size() >= 2) s += string{chr[1]} + chr[1];
else s += string{chr[1]} + chr[2];
}
else if(ask(nextstr) - s.size() == 2){
if(ask(s + chr[0] + chr[0] + chr[1] + s + chr[0] + chr[1] + chr[1]) - s.size() == 0){
if(ask(s + chr[1] + chr[0] + chr[1]) - s.size() >= 3) s += string{chr[1]} + chr[0] + chr[1];
else s += string{chr[1]} + chr[0] + chr[2];
}
else if(ask(s + chr[0] + chr[0] + chr[1] + s + chr[0] + chr[1] + chr[1]) - s.size() == 1){
if(ask(s + chr[0] + chr[2] + chr[1]) - s.size() >= 3) s += string{chr[0]} + chr[2] + chr[1];
else s += string{chr[0]} + chr[2] + chr[2];
}
else if(ask(s + chr[0] + chr[0] + chr[1] + s + chr[0] + chr[1] + chr[1]) - s.size() == 2){
if(ask(s + chr[0] + chr[0] + chr[2]) - s.size() >= 3) s += string{chr[0]} + chr[0] + chr[2];
else s += string{chr[0]} + chr[1] + chr[2];
}
else{
if(ask(s + chr[0] + chr[0] + chr[1]) - s.size() >= 3) s += string{chr[0]} + chr[0] + chr[1];
else s += string{chr[0]} + chr[1] + chr[1];
}
}
else{
if(ask(s + chr[0] + chr[0] + chr[0] + s + chr[0] + chr[1] + chr[0]) - s.size() >= 3){
if(ask(s + chr[0] + chr[0] + chr[0]) - s.size() >= 3) s += string{chr[0]} + chr[0] + chr[0];
else s += string{chr[0]} + chr[1] + chr[0];
}
else{
if(ask(s + chr[0] + chr[2] + chr[0]) - s.size() >= 3) s += string{chr[0]} + chr[2] + chr[0];
else s += string{chr[1]} + chr[0] + chr[0];
}
}
}
else if(n - s.size() == 2){
string nextstr = s + chr[0] + chr[0] + s + chr[0] + chr[1] + s + chr[1] + chr[0] + s + chr[1] + chr[1];
if(ask(nextstr) - s.size() == 0) s += chr[2];
else if(ask(nextstr) - s.size() == 1){
if(ask(s + chr[0] + chr[2]) - s.size() == 2) s += string{chr[0]} + chr[2];
else s += string{chr[1]} + chr[2];
}
else{
if(ask(s + chr[0] + chr[0] + s + chr[0] + chr[1]) - s.size() == 2){
if(ask(s + chr[0] + chr[0]) - s.size() == 2) s += string{chr[0]} + chr[0];
else s += string{chr[0]} + chr[1];
}
else{
if(ask(s + chr[1] + chr[0]) - s.size() == 2) s += string{chr[1]} + chr[0];
else s += string{chr[1]} + chr[1];
}
}
}
else if(n - s.size() == 1){
if(ask(s + chr[0]) - s.size() == 1) s += chr[0];
else if(ask(s + chr[1]) - s.size() == 1) s += chr[1];
else s += chr[2];
}
}
return s;
}
Compilation message (stderr)
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:44:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
44 | while(s.size() < n){
| ~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |