# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1142543 | joker2 | Combo (IOI18_combo) | C++20 | 0 ms | 0 KiB |
#include "combo.h"
#include <unordered_set>
#include <unordered_map>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
#include <numeric>
using namespace std;
std::string guess_sequence(int N) {
string S = "";
vector<char> btns = {'A','B','X','Y'};
while (S.length() != N) {
if (S.length() == 0) {
int coin = press("AB");
if (coin > 0) {
string s;
s += 'A';
coin = press(s);
if (coin == 1) {
S += 'A';
btns.erase(btns.begin());
} else {
S += 'B';
btns.erase(btns.begin()+1);
}
} else {
string s;
s += 'x';
coin = press(s);
if (coin == 1) {
S += 'X';
btns.erase(btns.begin()+2);
} else {
S += 'Y';
btns.erase(btns.begin()+3);
}
}
} else if (S.length() < N) {
string message = "";
message += S;
message += btns[0];
for (size_t i = 0; i < 3; i++) {
message += S;
message += btns[1];
message += btns[i];
}
int coin = press(message);
if (coin == S.length()+1) {
S += btns[0];
} else if (coin == S.length() + 2) {
S += btns[1];
} else {
S += btns[2];
}
} else {
string mess = S;
mess += btns[0];
mess += btns[1];
int coin = press();
if (coin > S.length()) {
mess = S;
mess += btns[0];
coin = press(mess);
if (coin == 1) {
S += btns[0];
} else {
S += btns[1];
}
} else {
S += btns[2];
}
}
}
return S;
}