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 "combo.h"
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
vector<char> ch = {'A', 'B', 'X', 'Y'};
char firstChar()
{
int coins;
coins = press(string(1, ch[0]) + string(1, ch[1]));
if (coins == 2) return ch[0];
else if (coins == 1) {
coins = press(string(1, ch[0]));
if (coins == 1) return ch[0];
else {
swap(ch[0], ch[1]);
return ch[0];
}
} else {
coins = press(string(1, ch[2]));
if (coins == 1) {
swap(ch[0], ch[2]);
return ch[0];
}
else {
swap(ch[0], ch[3]);
return ch[0];
}
}
}
char lastChar(string S)
{
int coins;
coins = press(S + string(1, ch[0]) + S + string(1, ch[1]));
if (coins == S.size() + 1) {
coins = press(S + string(1, ch[0]));
if (coins == S.size() + 1) return ch[0];
else return ch[1];
} else {
coins = press(S + string(1, ch[2]));
if (coins == S.size() + 1) return ch[2];
else return ch[3];
}
}
string guess_sequence(int N) {
string S = string(1, firstChar());
if (N == 1) return S;
int coins;
vector<string> str(4);
for (int i = 0; i < 4; ++i) str[i] = string(1, ch[i]);
for (int i = 2; i < N; ++i) {
// cerr << S << ": " << S + str[1] + str[1] + S + str[1] + str[2] + S + str[1] + str[3] + S + str[2];
coins = press(S + str[1] + str[1] + S + str[1] + str[2] + S + str[1] + str[3] + S + str[2]);
// cerr << " " << coins << endl;
if (coins == S.size() + 2) {
S += str[1];
} else if (coins == S.size() + 1) {
S += str[2];
} else {
S += str[3];
}
}
S += string(1, lastChar(S));
return S;
}
Compilation message (stderr)
combo.cpp: In function 'char lastChar(std::string)':
combo.cpp:41:15: 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 (coins == S.size() + 1) {
| ~~~~~~^~~~~~~~~~~~~~~
combo.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | if (coins == S.size() + 1) return ch[0];
| ~~~~~~^~~~~~~~~~~~~~~
combo.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | if (coins == S.size() + 1) return ch[2];
| ~~~~~~^~~~~~~~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:64:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | if (coins == S.size() + 2) {
| ~~~~~~^~~~~~~~~~~~~~~
combo.cpp:66:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | } else if (coins == S.size() + 1) {
| ~~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |