Submission #756511

#TimeUsernameProblemLanguageResultExecution timeMemory
756511FidiskCombo (IOI18_combo)C++17
100 / 100
35 ms588 KiB
#include <bits/stdc++.h>
#include <combo.h>
using namespace std;

#define oo 1e18
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;

const ll mod=1e9+7;

string guess_sequence(int n) {
    int cnt=0;
    int i,k;
    string str="",ch[5];
    if (n==1) {
        if (press("A")) {
            return "A";
        }
        else if (press("B")) {
            return "B";
        }
        else if (press("X")) {
            return "X";
        }
        else {
            return "Y";
        }
    }
    /*
    else if (n==2) {
        //We should have 4 query for this
        k=press("ABAXAYB");
        if (k==2) {
            //First is A
            k=press("ABAX");
            if (k==2) {
                //AB or AX
                if (press("AB")==2) {
                    return "AB";
                }
                else {
                    return "AX";
                }
            }
            else {
                return "AY";
            }
        }
        else if (k==1) {
            //First is B
            k=press("BABX");
            if (k==2) {
                //BA or BX
                if (press("BA")==2) {
                    return "BA";
                }
                else {
                    return "BX";
                }
            }
            else {
                return "BY";
            }
        }
        else {
            //First is either X or Y
            k=press("X");
            if (k) {
                //First is X
                k=press("XAXB");
                if (k==2) {
                    //XA or XB
                    if (press("XA")==2) {
                        return "XA";
                    }
                    else {
                        return "XB";
                    }
                }
                else {
                    return "XY";
                }
            }
            else {
                //First is Y
                k=press("YAYB");
                if (k==2) {
                    //YA or YB
                    if (press("YA")==2) {
                        return "YA";
                    }
                    else {
                        return "YB";
                    }
                }
                else {
                    return "YX";
                }
            }
        }
    }
    */
    else if (n>=2) {
        //5 query, so
        //Find first character - Take 2
        //Find second character - Take 1
        //2 for the last
        k=press("AB");
        if (k) {
            if (press("A")) {
                str="A";
            }
            else {
                str="B";
            }
        }
        else {
            if (press("X")) {
                str="X";
            }
            else {
                str="Y";
            }
        }
        /*
        if (k==2) {
            //First is A
            str+="A";
        }
        else if (k==1) {
            //First is B
            str+="B";
        }
        else if (k==0) {
            //First is either X or Y
            if (press("X")) {
                //First is X
                str+="X";
            }
            else {
                //First is Y
                str+="Y";
            }
        }
        */
        if (str!="A") {
            cnt++;
            ch[cnt]="A";
        }
        if (str!="B") {
            cnt++;
            ch[cnt]="B";
        }
        if (str!="X") {
            cnt++;
            ch[cnt]="X";
        }
        if (str!="Y") {
            cnt++;
            ch[cnt]="Y";
        }
        for (i=3;i<=n;i++) {
            k=press(str+ch[1]+ch[1]+str+ch[1]+ch[2]+str+ch[1]+ch[3]+str+ch[2]);
            if (k==i) {
                str+=ch[1];
            }
            else if (k==i-1) {
                str+=ch[2];
            }
            else {
                str+=ch[3];
            }
        }
        if (press(str+ch[1]+str+ch[2])>=n) {
            if (press(str+ch[1])==n) {
                return str+ch[1];
            }
            else {
                return str+ch[2];
            }
        }
        else {
            return str+ch[3];
        }
    }
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:27:16: warning: control reaches end of non-void function [-Wreturn-type]
   27 |     string str="",ch[5];
      |                ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...