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 <bits/stdc++.h>
#include "combo.h"
using namespace std;
/*
int press(string s) {
cout << s << '\n';
cout.flush();
int val;
cin >> val;
return val;
}
*/
string Guess_first() {
if (press("AB")) {
if (press("A")) return "A";
return "B";
}
else {
if (press("X")) return "X";
return "Y";
}
}
bool Guess_last(string f) {
int n = (int)f.length();
if (press(f) == n) {
return true;
}
return false;
}
string guess_sequence(int n) {
string s = Guess_first();
string ans = s;
string c = "ABXY";
for (int i = 0 ; i < 4 ; i++) {
if (c[i] == s[0]) {
c.erase(c.begin() + i);
break;
}
}
auto Create = [&](string cur) {
cur += c[0];
cur += s;
cur += c[1];
cur += c[0];
cur += s;
cur += c[1];
cur += c[1];
cur += s;
cur += c[1];
cur += c[2];
assert((int)cur.length() <= 4 * n);
return cur;
};
for (int i = 1 ; i < n - 1 ; i += 1) {
string cur = Create(ans);
int foo = press(cur);
if (foo == i) {
ans += c[2];
}
else if (foo == i + 1) {
ans += c[0];
}
else {
ans += c[1];
}
s = ans;
}
if (n > 1) {
bool ok = false;
for (int i = 0 ; i < 2 ; i++) {
string cur = ans + c[i];
if (Guess_last(cur)) {
ok = true;
ans += c[i];
break;
}
}
if (!ok) {
ans += c[2];
}
}
return ans;
}
/*
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string ans = guess_sequence(n);
cout << ans << '\n';
return 0;
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |