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;
#define fr(m,n,k) for(int m=n;m<=k;m++)
#define sz size()
#define all(v) v.begin(), v.end()
int n;
string guess_sequence(int N) {
    n = N; string v = "ABXY"; string p, s; int a;
    p = "AB";
    int x = press(p);
    if (x) {
        p = "A"; int x = press(p);
        if (x == 1) a = 0;
        else a = 1;
    }
    else {
        p = "X"; int x = press(p);
        if (x == 1) a = 2;
        else a = 3;
    }
    s = v[a];
    if (n == 1) return s;
    vector<int> rem = {0, 1, 2, 3}; rem.erase(find(all(rem), a));
    fr(i, 2, n - 1) {
        p = "";
        for (auto z : rem) p += s + v[rem[0]] + v[z];
        p += s + v[rem[1]];
        int x = press(p);
        if (x == i) {
            a = rem[2];
        }
        else if (x == i + 1) {
            a = rem[1];
        }
        else {
            a = rem[0];
        }
        s += v[a];
    }
    p = s + "A" + s + 'B';
    x = press(p);
    if (x >= n) {
        p = s + "A"; int x = press(p);
        if (x == n) a = 0;
        else a = 1;
    }
    else {
        p = s + "X"; int x = press(p);
        if (x == n) a = 2;
        else a = 3;
    }
    s += v[a];
    return s;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |