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 <bits/stdc++.h>
#define ALL(x) x.begin(), x.end()
using namespace std;
vector<char> buttons = {'A', 'B', 'X', 'Y'};
string S;
string conv(const string &in)
{
string ret = in;
ret = regex_replace(ret, std::regex("r"), S);
ret = regex_replace(ret, std::regex("a"), string{buttons[0]});
ret = regex_replace(ret, std::regex("b"), string{buttons[1]});
ret = regex_replace(ret, std::regex("c"), string{buttons[2]});
return ret;
}
string guess_sequence(int N)
{
buttons = {'A', 'B', 'X', 'Y'};
S = "";
int r = press("AB");
if (r == 2)
{
S = "AB";
buttons.erase(buttons.begin());
}
else if (r == 1)
{
r = press("A");
if (r == 1)
{
S = "A";
buttons.erase(buttons.begin());
}
else
{
S = "B";
buttons.erase(buttons.begin() + 1);
}
}
else
{
r = press("X");
if (r == 1)
{
S = "X";
buttons.erase(buttons.begin() + 2);
}
else
{
S = "Y";
buttons.erase(buttons.begin() + 3);
}
}
while (N - S.size() > 1)
{
int s = S.size();
r = press(conv("raarabrba"));
if (r == s)
{
S += conv("c");
}
else if (r == s + 1)
{
r = press(conv("rbb"));
if (r == s)
{
S += conv("ac");
}
else if (r == s + 1)
{
S += conv("bc");
}
else
{
S += conv("bb");
}
}
else
{
r = press(conv("raa"));
if (r == s)
{
S += conv("ba");
}
else if (r == s + 1)
{
S += conv("ab");
}
else
{
S += conv("aa");
}
}
}
if (S.size() == N - 1)
{
r = press(conv("ra"));
if (r == N)
{
S += conv("a");
}
else
{
r = press(conv("rb"));
if (r == N)
{
S += conv("b");
}
else
{
S += conv("c");
}
}
}
if (S.size() > N)
S.erase(S.begin() + N, S.end());
return S;
}
Compilation message (stderr)
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:98:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
98 | if (S.size() == N - 1)
| ~~~~~~~~~^~~~~~~~
combo.cpp:118:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
118 | if (S.size() > N)
| ~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |