# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1128561 | mbalsells | Combo (IOI18_combo) | C++20 | 0 ms | 396 KiB |
#include "combo.h"
using namespace std;
// ABXY
string buttons = "ABXY";
int get_index(string& s){
for (int i = 0; i < 4; ++i){
if (s[0] == buttons[i]) return i;
}
}
char get_first(){
if (press("AB") == 1){
if (press("A")) return 'A';
else return 'B';
}
else {
if (press("X") == 1) return 'X';
else return 'Y';
}
}
char get_next(string s){
int index = get_index(s);
string left_buttons;
for (int i = 1; i <= 3; ++i){
left_buttons.push_back(buttons[(index + i) % 4]);
}
int l = s.size();
string query = s;
query.push_back(left_buttons[0]);
for (int i = 0; i < 3; ++i){
query += s;
query.push_back(left_buttons[1]);
query.push_back(left_buttons[i]);
}
int response = press(query);
if (response == l) return left_buttons[2];
if (response == l + 1) return left_buttons[0];
return left_buttons[1];
}
char get_last(string& s){
int index = get_index(s);
string left_buttons;
for (int i = 1; i <= 3; ++i){
left_buttons.push_back(buttons[(index + i) % 4]);
}
int l = s.size();
string query = s;
query.push_back(left_buttons[0]);
if (press(query) == l + 1) return left_buttons[0];
query = s;
query.push_back(left_buttons[1]);
if (press(query) == l + 1) return left_buttons[1];
return left_buttons[2];
}
std::string guess_sequence(int N) {
string ans;
ans.push_back(get_first());
if (N == 1) return ans;
for (int i = 2; i < N; ++i){
ans.push_back(get_next(ans));
}
ans.push_back(get_last(ans));
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |