Submission #1248567

#TimeUsernameProblemLanguageResultExecution timeMemory
1248567antonnCombo (IOI18_combo)C++20
30 / 100
15 ms500 KiB
#include "combo.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;


int ask(int n, string s, char c) {
    string query = s;
    for (int i = 1; i <= n; ++i) query += c;
    return press(query);
}

string guess_sequence(int n) {
    string s = "";
    if (press("A") == 1) s += "A";
    else if (press("B") == 1) s += "B";
    else if (press("X") == 1) s += "X";
    else s += "Y";
    
    if (n == 1) return s;
    
    vector<char> c;
    for (auto ch : {'A', 'B', 'X', 'Y'}) {
        if (ch != s[0]) {
            c.push_back(ch);
        }
    }
    
    while (s.size() < n) {
        vector<char> c;
        for (auto ch : {'A', 'B', 'X', 'Y'}) {
            if (ch != s[0] && ch != s.back()) {
                c.push_back(ch);
            }
        }
        int len = s.size();
        int x = ask(n, s, c[0]);
        if (x != len) {
            for (int j = 1; j <= x - len; ++j) s += c[0];
        } else {
            x = ask(n, s, c[1]);
            if (x != len) {
                for (int j = 1; j <= x - len; ++j) s += c[1];
            } else {
                x = ask(n, s, c[2]);
                for (int j = 1; j <= x - len; ++j) s += c[2];
            } 
        }
    }
    return s;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...