Submission #1226978

#TimeUsernameProblemLanguageResultExecution timeMemory
1226978Hamed_GhaffariCombo (IOI18_combo)C++17
100 / 100
7 ms484 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

string guess_sequence(int N) {
    string chs = "ABXY", ans;
    if(press("AB")) {
        if(press("A")) ans.push_back('A');
        else ans.push_back('B');
    }
    else if(press("X")) ans.push_back('X');
    else ans.push_back('Y');
    if(N==1) return ans;
    for(int i=0; i<4; i++)
        if(chs[i]==ans[0]) {
            swap(chs[i], chs.back());
            break;
        }
    chs.pop_back();
    for(int i=1; i+1<N; i++) {
        string ask = ans;
        ask.push_back(chs[0]);
        ask += ans;
        ask.push_back(chs[1]);
        ask.push_back(chs[0]);
        ask += ans;
        ask.push_back(chs[1]);
        ask.push_back(chs[1]);
        ask += ans;
        ask.push_back(chs[1]);
        ask.push_back(chs[2]);
        int res = press(ask);
        if(res==i) ans.push_back(chs[2]);
        else if(res==i+1) ans.push_back(chs[0]);
        else ans.push_back(chs[1]);
    }
    ans.push_back(chs[0]);
    if(press(ans)==N) return ans;
    ans.back() = chs[1];
    if(press(ans)==N) return ans;
    ans.back() = chs[2];
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...