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 ans = "";
void tr(string c1, string c2, string c3) {
int cur = press(ans + c1 + ans + c2+c1 + ans + c2+c2 + ans + c2+c3);
if (ans.size() == cur)ans.push_back(c3[0]);
else if (ans.size() == cur - 1)ans.push_back(c1[0]);
else if (ans.size() == cur - 2)ans.push_back(c2[0]);
}
string guess_sequence(int N) {
if (N == 1) {
int cur = 0;
for (string c : {"A", "B", "X"}) {
cur = press(c);
if (cur == 1){ans = c;break;}
}
if (ans.empty())ans = "Y";
return ans;
}
int cur = 0;
cur = press("AB");
if (cur == 2)ans = "AB";
else if (cur == 1) {
if (press("A") == 1)ans = "A";
else ans = "B";
} else {
if (press("X") == 1)ans = "X";
else ans = "Y";
}
for (int id = ans.size() + 1; id < N; id++) {
if (ans[0] == 'A')tr("B", "X", "Y");
if (ans[0] == 'B')tr("A", "X", "Y");
if (ans[0] == 'X')tr("A", "B", "Y");
if (ans[0] == 'Y')tr("A", "B", "X");
}
if (ans.size() == N - 1) {
int cnt = 0;
for (string c : {"A", "B", "X", "Y"}) {
if (c[0] == ans[0])continue;
if (++cnt == 3)return ans + c;
if (press(ans + c) == N)return ans + c;
}
}
// if (ans.size() == N - 2) {
// if (press(ans + "A" + ans + "B") == ans.size() + 1) {
// if (press(ans + "A") == ans.size() + 1)return ans + "A";
// return ans + "B";
// }
// if (press(ans + "X") == ans.size() + 1)return ans + "X";
// return ans + "Y";
// }
return ans;
}
Compilation message (stderr)
combo.cpp: In function 'void tr(std::string, std::string, std::string)':
combo.cpp:9:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
9 | if (ans.size() == cur)ans.push_back(c3[0]);
| ~~~~~~~~~~~^~~~~~
combo.cpp:10:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
10 | else if (ans.size() == cur - 1)ans.push_back(c1[0]);
| ~~~~~~~~~~~^~~~~~~~~~
combo.cpp:11:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
11 | else if (ans.size() == cur - 2)ans.push_back(c2[0]);
| ~~~~~~~~~~~^~~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:40:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | if (ans.size() == N - 1) {
| ~~~~~~~~~~~^~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |