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>
#ifndef LOCAL
#include "combo.h"
#endif
#ifdef LOCAL
namespace {
constexpr int MAX_N = 2000;
constexpr int MAX_NUM_MOVES = 8000;
int N;
std::string S;
int num_moves;
void wrong_answer(const char *MSG) {
printf("Wrong Answer: %s\n", MSG);
exit(0);
}
} // namespace
int press(std::string p) {
if (++num_moves > MAX_NUM_MOVES) {
wrong_answer("too many moves");
}
int len = p.length();
if (len > 4 * N) {
wrong_answer("invalid press");
}
for (int i = 0; i < len; ++i) {
if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
wrong_answer("invalid press");
}
}
int coins = 0;
for (int i = 0, j = 0; i < len; ++i) {
if (j < N && S[j] == p[i]) {
++j;
} else if (S[0] == p[i]) {
j = 1;
} else {
j = 0;
}
coins = std::max(coins, j);
}
return coins;
}
#endif
using namespace std;
string guess_sequence(int n) {
string ret, s;
auto guess = [&]() {
if (!ret.size()) {
int x = press(ret + "AB");
if (x) ret = press("A") ? "A" : "B";
else ret = press("X") ? "X" : "Y";
for (auto ch : "ABXY") if (string(1, ch) != ret) s.push_back(ch);
return;
}
if (press(ret + s[0] + ret + s[1]) - ret.size()) {
if (press(ret + s[0]) - ret.size()) ret += s[0];
else ret += s[1];
} else ret += s[2];
};
guess();
while (ret.size() < n) {
if (ret.size() * 4 + 7 <= 4 * n) {
int x = press(ret + s[0] + s[0] + ret + s[0] + s[1] + ret + s[0] + s[2] + ret + s[1]);
char nxt = (x == ret.size() ? s[2] : x == ret.size() + 1 ? s[1] : s[0]);
ret += nxt;
} else guess();
}
return ret;
}
#ifdef LOCAL
int main() {
char buffer[MAX_N + 1];
if (scanf("%s", buffer) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
S = buffer;
N = S.length();
num_moves = 0;
std::string answer = guess_sequence(N);
if (answer != S) {
wrong_answer("wrong guess");
exit(0);
}
printf("Accepted: %d\n", num_moves);
return 0;
}
#endif
Compilation message (stderr)
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:74:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
74 | while (ret.size() < n) {
| ~~~~~~~~~~~^~~
combo.cpp:75:28: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
75 | if (ret.size() * 4 + 7 <= 4 * n) {
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~
combo.cpp:77:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | char nxt = (x == ret.size() ? s[2] : x == ret.size() + 1 ? s[1] : s[0]);
| ~~^~~~~~~~~~~~~
combo.cpp:77:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | char nxt = (x == ret.size() ? s[2] : x == ret.size() + 1 ? s[1] : s[0]);
| ~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |