Submission #1200453

#TimeUsernameProblemLanguageResultExecution timeMemory
1200453tamzidCombo (IOI18_combo)C++20
97 / 100
7 ms484 KiB
#include <bits/stdc++.h>
#include "combo.h"
using namespace std;

string guess_sequence(int N) {
    string S;
    // Determine the first character
    if (press("A") > 0) {
        S = "A";
    } else if (press("B") > 0) {
        S = "B";
    } else if (press("X") > 0) {
        S = "X";
    } else {
        S = "Y";
    }
    
    if (N == 1) return S;
    
    vector<char> remaining;
    for (char c : {'A', 'B', 'X', 'Y'}) {
        if (c != S[0]) {
            remaining.push_back(c);
        }
    }
    
    for (int i = 1; i < N - 1; ++i) {
        string query = S + remaining[0] + S + remaining[1] + remaining[0] + S + remaining[1] + remaining[1] + S + remaining[1] + remaining[2];
        int coins = press(query);
        if (coins == i + 1) {
            S += remaining[0];
        } else if (coins == i + 2) {
            S += remaining[1];
        } else {
            S += remaining[2];
        }
    }
    
    // Handle the last character
    if (N > 1) {
        string query1 = S + remaining[0];
        if (press(query1) == N) {
            S += remaining[0];
        } else {
            string query2 = S + remaining[1];
            if (press(query2) == N) {
                S += remaining[1];
            } else {
                S += remaining[2];
            }
        }
    }
    
    return S;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...