Submission #1127596

#TimeUsernameProblemLanguageResultExecution timeMemory
1127596Elwino008Combo (IOI18_combo)C++20
94 / 100
30 ms22184 KiB
#include "combo.h"
#include <bits/stdc++.h>
#include <time.h>

using namespace std;

#define pb push_back
#define all(v) v.begin(), v.end()

mt19937 rndm(time(NULL));

string f(string a, int N, char st){
    int n=a.size();
    if(n==N-1){
        return a;
    }
    string q="";
    if(st=='A'){
        q+=a;
        q+='B';
        q+=a;
        q+="XB";
        q+=a;
        q+="XX";
        q+=a;
        q+="XY";
        int qwe=press(q);
        if(qwe==n){
            a+='Y';
        }
        else if(qwe==n+1){
            a+='B';
        }
        else{
            a+='X';
        }
    }
    else if(st=='B'){
        q+=a;
        q+='A';
        q+=a;
        q+="XA";
        q+=a;
        q+="XX";
        q+=a;
        q+="XY";
        int qwe=press(q);
        if(qwe==n){
            a+='Y';
        }
        else if(qwe==n+1){
            a+='A';
        }
        else{
            a+='X';
        }
    }
    else if(st=='X'){
        q+=a;
        q+='A';
        q+=a;
        q+="BA";
        q+=a;
        q+="BB";
        q+=a;
        q+="BY";
        int qwe=press(q);
        if(qwe==n){
            a+='Y';
        }
        else if(qwe==n+1){
            a+='A';
        }
        else{
            a+='B';
        }
    }
    else{
        q+=a;
        q+='A';
        q+=a;
        q+="BA";
        q+=a;
        q+="BB";
        q+=a;
        q+="BX";
        int qwe=press(q);
        if(qwe==n){
            a+='X';
        }
        else if(qwe==n+1){
            a+='A';
        }
        else{
            a+='B';
        }
    }
    return f(a, N, st);

}

std::string guess_sequence(int N) {
    vector<string>strt;
    strt.pb("X");
    strt.pb("A");
    strt.pb("Y");
    strt.pb("B");
    sort(all(strt));
    shuffle(all(strt), rndm);
    char st;
    string a="";
    int ind=0;
    int q=press(strt[ind]);
    while(q!=1){
        ind++;
        if(ind==3){
            break;
        }
        q=press(strt[ind]);
    }
    st=strt[ind][0];
    a+=st;
    if(N==1){
        return a;
    }
    string ans=f(a, N, st);
    ind=0;
    //shuffle(all(strt), rndm);
    q=press(ans+strt[ind]);
    while(q!=N){
        ind++;
        if(ind==3){
            break;
        }
        q=press(ans+strt[ind]);
    }
    ans+=strt[ind];
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...