Submission #765481

#TimeUsernameProblemLanguageResultExecution timeMemory
765481typ_ikCombo (IOI18_combo)C++17
94 / 100
24 ms752 KiB
#include "combo.h"
#include <bits/stdc++.h>

#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define watch(x) cout << (#x) << " : " << x << '\n'
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

//const string hidden = "XYYYYYYY";
//
//int press(string s) {
//    cout << "ask " << s << '\n';
//    int res = 0, pt = 0;
//    for (int i = 0; i < (int)s.size(); i++) {
//        if (hidden[pt] == s[i])
//            pt++;
//        else
//            pt = 0;
//        res = max(res, pt);
//        if (pt == (int)hidden.size())
//            break;
//    }
//    return res;
//}

string make_string(char x) {
    string res;
    res += x;
    return res;
}

string guess_sequence(int N) {
    // guess first letter

    int n = N;

    const vector<char> symb = {'A', 'B', 'X', 'Y'};
    vector <int> order(4);
    iota(all(order), 0);
    random_shuffle(all(order));

    char blocked = '.';
    for (int i = 0; i < 4; i++) {
        if (i == 3) {
            blocked = symb[order[i]];
        } else {
            int c = press(make_string(symb[order[i]]));
            if (c == 0)
                continue;
            blocked = symb[order[i]];
            break;
        }
    }

    assert(blocked != '.');

    int pos = -1;
    for (int i = 0; i < 4; i++)
        if (symb[order[i]] == blocked)
            pos = i;

    assert(pos != -1);

    order.erase(order.begin() + pos);

    assert((int)order.size() == 3);

    vector <char> ss;
    for (auto i : order)
        ss.push_back(symb[i]);

    string pref = make_string(blocked);

    if (n == 1)
        return pref;

    for (int i = 1; i + 1 < n; i++) {
        vector <string> parts;
        parts.push_back(pref+ss[0]);
        parts.push_back(pref+ss[1]+ss[0]);
        parts.push_back(pref+ss[1]+ss[1]);
        parts.push_back(pref+ss[1]+ss[2]);


        string tot = "";
        for (auto& c : parts)
            tot += c;
        assert((int)tot.size() <= 4 * n);

        int c = press(tot);

        if (c == i)
            pref += ss[2];
        else if (c == i + 1)
            pref += ss[0];
        else if (c == i + 2)
            pref += ss[1];
    }

    assert((int)pref.size() == n - 1);

    for (auto& x : ss) {
        int c = press(pref+x);
        if (c != n)
            continue;
        pref += x;
        break;
    }

    return pref;
}

//main() {
//    srand(time(NULL));
//    boost;
//
//    string res = guess_sequence((int)(hidden.size()));
//
//    cout << "res = " << res << '\n';
//    cout << (res == hidden ? "correct" : "incorrect") << '\n';
//
//    return 0;
//}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...