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>
using namespace std;
using ll = long long int;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define F first
#define S second
ll min(ll x, ll y){
return ((x < y) ? x : y);
}
ll max(ll x, ll y){
return ((x > y) ? x : y);
}
/*
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;
}
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;
}
//*/
class Solver{
private:
string outp;
ll n;
void getFirstChar(){
ll res = press("AB");
if (res == 2) outp = "AB";
else if (res == 1){
res = press("A");
if (res == 1) outp = "A";
else outp = "B";
}else{
res = press("C");
if (res == 1) outp = "C";
else outp = "D";
}
}
public:
Solver(ll n): n(n){
getFirstChar();
vector<char> ogchoices = {'A','B','X','Y'};
vector<char> choices;
for (auto c: ogchoices){
if (c != outp[0]) choices.push_back(c);
}
while (outp.size() < n){
ll startSize = outp.size();
bool found = false;
for (ll i = 0; 2 > i; i++){
string query = outp;
query.push_back(choices[i]);
ll res = press(query);
if (res == query.size()){
found = true;
outp.push_back(choices[i]);
break;
}
}
if (!found){
outp.push_back(choices[2]);
}
assert(startSize+1 == outp.size());
}
}
string solve(){
return outp;
}
};
string guess_sequence(int n) {
Solver solver(n);
return solver.solve();
}
Compilation message (stderr)
combo.cpp: In constructor 'Solver::Solver(ll)':
combo.cpp:113:28: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
113 | while (outp.size() < n){
| ~~~~~~~~~~~~^~~
combo.cpp:120:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | if (res == query.size()){
| ~~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from combo.cpp:2:
combo.cpp:129:32: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
129 | assert(startSize+1 == outp.size());
| ~~~~~~~~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |