# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1206948 | a1m4n | Combo (IOI18_combo) | C++20 | 0 ms | 0 KiB |
#ifdef AIMAN
#define _GLIBCXX_DEBUG
#endif
#include "combo.h"
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
using ll = long long;
const ll INF = 1e9;
using namespace std;
int press(string s) {
cout << s << "\n" << flush;
int res;
if (!(cin >> res)) exit(0);
return res;
}
string guess_sequence(int n) {
string ans;
int matched = 0;
int x = press("AB");
if (x == 0) {
x = press("X");
ans += (x == 1 ? 'X' : 'Y');
} else {
x = press("A");
ans += (x == 1 ? 'A' : 'B');
}
matched = 1;
while (matched + 2 <= n) {
char start = ans[0];
if (start == 'A') {
x = press(ans + "BB" + ans + "BX" + ans + "BY" + ans + "X");
if (x == matched) ans += 'Y';
else if (x == matched + 1) ans += 'X';
else ans += 'B';
}
else if (start == 'B') {
x = press(ans + "AA" + ans + "AX" + ans + "AY" + ans + "X");
if (x == matched) ans += 'Y';
else if (x == matched + 1) ans += 'X';
else ans += 'A';
}
else if (start == 'X') {
x = press(ans + "AA" + ans + "AB" + ans + "AY" + ans + "B");
if (x == matched) ans += 'Y';
else if (x == matched + 1) ans += 'B';
else ans += 'A';
}
else {
x = press(ans + "BB" + ans + "BX" + ans + "BA" + ans + "X");
if (x == matched) ans += 'A';
else if (x == matched + 1) ans += 'X';
else ans += 'B';
}
matched++;
}
if (matched == n - 1) {
char start = ans[0];
if (start == 'A') {
x = press(ans + "B");
if (x == n) ans += 'B';
else {
x = press(ans + "X");
ans += (x == n ? 'X' : 'Y');
}
}
else if (start == 'B') {
x = press(ans + "A");
if (x == n) ans += 'A';
else {
x = press(ans + "X");
ans += (x == n ? 'X' : 'Y');
}
}
else if (start == 'X') {
x = press(ans + "A");
if (x == n) ans += 'A';
else {
x = press(ans + "B");
ans += (x == n ? 'B' : 'Y');
}
}
else {
x = press(ans + "B");
if (x == n) ans += 'B';
else {
x = press(ans + "X");
ans += (x == n ? 'X' : 'A');
}
}
}
return ans;
}