Submission #1185566

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

string solve(string x, string y, string z, string k, int N) {
    while (k.size() < N - 1) {
        int sz = k.size();
        string temp = k + x + x + k + x + y + k + x + z + k + y;
        int res = press(temp);

        if (res == sz) {
            k += z;
        } else if (res == sz + 1) {
            k += y;
        } else if (res == sz + 2) {
            k += x;
        } else {
            // Defensive exit in case of unexpected press result
            exit(1);
        }
    }

    // Add final character
    for (string c : {x, y, z}) {
        string temp = k + c;
        if (press(temp) == N) {
            return temp;
        }
    }

    // Should not reach here if input constraints are respected
    return "";
}

string guess_sequence(int N) {
    string ans;

    if (press("ab") >= 1) {
        if (press("a") == 1) {
            ans = solve("x", "y", "b", "a", N);
        } else {
            ans = solve("x", "y", "a", "b", N);
        }
    } else {
        if (press("x") == 1) {
            ans = solve("b", "y", "a", "x", N);
        } else {
            ans = solve("x", "b", "a", "y", N);
        }
    }

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...