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 v = "ABXY";
void Guess_Next(string &s, int N) {
if(s.size() == N - 1) return;
// Will do this very ugly
if(s[0] == 'A') {
int answ = press(s + "B" + s + "XB" + s + "XY" + s + "XX");
if(answ == s.size() + 1) {
s += "B";
Guess_Next(s, N);
} else if(answ == s.size() + 2) {
s += "X";
Guess_Next(s, N);
} else if(answ == s.size()) {
s += "Y";
Guess_Next(s, N);
}
} else if(s[0] == 'B') {
int answ = press(s + "A" + s + "XA" + s + "XY" + s + "XX");
if(answ == s.size() + 1) {
s += "A";
Guess_Next(s, N);
} else if(answ == s.size() + 2) {
s += "X";
Guess_Next(s, N);
} else if(answ == s.size()) {
s += "Y";
Guess_Next(s, N);
}
} else if(s[0] == 'X') {
int answ = press(s + "A" + s + "BA" + s + "BY" + s + "BB");
if(answ == s.size() + 1) {
s += "A";
Guess_Next(s, N);
} else if(answ == s.size() + 2) {
s += "B";
Guess_Next(s, N);
} else if(answ == s.size()) {
s += "Y";
Guess_Next(s, N);
}
} else { // s[0] == 'Y'
int answ = press(s + "A" + s + "BA" + s + "BX" + s + "BB");
if(answ == s.size() + 1) {
s += "A";
Guess_Next(s, N);
} else if(answ == s.size() + 2) {
s += "B";
Guess_Next(s, N);
} else if(answ == s.size()) {
s += "X";
Guess_Next(s, N);
}
}
}
string guess_sequence(int N) {
string ans = "";
// Guessing the first character
if(press("AB") > 0) {
if(press("A") > 0)
ans = "A";
else ans = "B";
} else { // press("XY") > 0
if(press("X") > 0)
ans = "X";
else ans = "Y";
}
if(N == 1) return ans;
Guess_Next(ans, N);
// Guessing the last character
for(int i = 0; i < v.size() - 1; i++) {
if(v[i] != ans[0] && press(ans + v[i]) == N) {
ans += v[i];
i = v.size();
}
}
if(ans.size() == N - 1)
ans += v.back();
return ans;
}
Compilation message (stderr)
combo.cpp: In function 'void Guess_Next(std::string&, int)':
combo.cpp:8:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
8 | if(s.size() == N - 1) return;
| ~~~~~~~~~^~~~~~~~
combo.cpp:15:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | if(answ == s.size() + 1) {
| ~~~~~^~~~~~~~~~~~~~~
combo.cpp:18:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | } else if(answ == s.size() + 2) {
| ~~~~~^~~~~~~~~~~~~~~
combo.cpp:21:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | } else if(answ == s.size()) {
| ~~~~~^~~~~~~~~~~
combo.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if(answ == s.size() + 1) {
| ~~~~~^~~~~~~~~~~~~~~
combo.cpp:31:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | } else if(answ == s.size() + 2) {
| ~~~~~^~~~~~~~~~~~~~~
combo.cpp:34:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | } else if(answ == s.size()) {
| ~~~~~^~~~~~~~~~~
combo.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | if(answ == s.size() + 1) {
| ~~~~~^~~~~~~~~~~~~~~
combo.cpp:44:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | } else if(answ == s.size() + 2) {
| ~~~~~^~~~~~~~~~~~~~~
combo.cpp:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | } else if(answ == s.size()) {
| ~~~~~^~~~~~~~~~~
combo.cpp:54:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | if(answ == s.size() + 1) {
| ~~~~~^~~~~~~~~~~~~~~
combo.cpp:57:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | } else if(answ == s.size() + 2) {
| ~~~~~^~~~~~~~~~~~~~~
combo.cpp:60:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | } else if(answ == s.size()) {
| ~~~~~^~~~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i = 0; i < v.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~
combo.cpp:92:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
92 | if(ans.size() == N - 1)
| ~~~~~~~~~~~^~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |