Submission #1248629

#TimeUsernameProblemLanguageResultExecution timeMemory
1248629countlessCombo (IOI18_combo)C++20
0 / 100
0 ms412 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define sp <<" "<<
#define endl "\n"
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string guess_sequence(int N) {
    string p = "";

    vector<char> st = {'A', 'B', 'X', 'Y'};
    shuffle(all(st), rng);

    // find first character in 2 queries
    {
        p = st[0] + st[1];
        int x = press(p);

        if (x >= 1) {
            p = st[0];
            x = press(p);

            p = (x == 1 ? st[0] : st[1]);
        } else {
            p = st[2];
            x = press(p);

            p = (x == 1 ? st[2] : st[3]);
        }

        st.erase(find(all(st), p[0]));
    }

    // find the rest of the characters
    {
        int t = 2;
        for (; t <= N; t++) {
            shuffle(all(st), rng);
            string q = "";
            q += p + st[1];
            q += p + st[2] + st[0];
            q += p + st[2] + st[1];
            q += p + st[2] + st[2];

            if (q.size() > 4 * N) break;

            int x = press(q);

            if (x == t-1) {
                p += st[0];
            } else if (x == t) {
                p += st[1];
            } else if (x == t+1) {
                p += st[2];
            } else assert(0);
        }

        // t == N
        for (; t <= N; t++) {
            shuffle(all(st), rng);
            string q;
            for (int i = 0; i < 2; i++) {
                q = (p + st[i]);
                // cerr << q << endl;
                int x = press(q);
                if (x == t) {
                    p = q;
                    break;
                }
            }

            if (p.size() != t) {
                p += st[2];
            }
        }
    }

    // cerr << p << endl;
    return p;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...