Submission #1211843

#TimeUsernameProblemLanguageResultExecution timeMemory
1211843lukasuliashviliCombo (IOI18_combo)C++20
94 / 100
8 ms484 KiB
#include<bits/stdc++.h>
#include "combo.h"
using namespace std;

std::string guess_sequence(int N) {
    /*A B X Y*/
    if (N==3) {
        string all = "ABXY";
        string candidate;

        for (char c1 : all) {
            for (char c2 : all) {
                for (char c3 : all) {
                    candidate = {c1, c2, c3};
                    if (press(candidate) == 3) {
                        return candidate;
                    }
                }
            }
        }
        return "";
    }
    string p="";
    string p1="AB";
    int ans=press(p1);
    if (ans==1 or ans==2) {
        string psome="A";
        int ansk=press(psome);
        if (ansk==1) {
            p+=psome;
        }
        else {
            p+='B';
        }

    }
    if (ans==0) {
        string p2="X";
        int ans2=press(p2);
        if (ans2==1) {
            p+=p2;
        }
        else {
            p+='Y';
        }
    }
    if (N==2) {
        int pas=0;
        pas=press(p+"A");
        if (pas==2) {
            return p+"A";
        }
        pas=press(p+"B");
        if (pas==2) {
            return p+"B";
        }
        pas=press(p+"X");
        if (pas==2) {
            return p+"X";
        }
        pas=press(p+"Y");
        if (pas==2) {
            return p+"Y";
        }

    }
    if (N==1) {
        return p;
    }
    char fix1, fix2, fix3;

    if (p[0] == 'X') {
        fix1 = 'A';
        fix2 = 'B';
        fix3 = 'Y';
    }
    if (p[0] == 'Y') {
        fix1 = 'A';
        fix2 = 'B';
        fix3 = 'X';
    }
    if (p[0] == 'A') {
        fix1 = 'X';
        fix2 = 'B';
        fix3 = 'Y';
    }
    if (p[0] == 'B') {
        fix1 = 'A';
        fix2 = 'X';
        fix3 = 'Y';
    }

    while (p.size() <N-1) {
        string q = p + fix1 + p + fix2 + fix3 + p + fix2 + fix1 + p + fix2 + fix2;
        int res = press(q);
        if (res == p.size()) {
            p += fix3;
        } else if (res == p.size() + 1) {
            p += fix1;
        } else {
            p += fix2;
        }
    }
    if (press(p+fix1)==p.size()+1) {
        return p+fix1;
    }
    else {
        if (press(p+fix2)==p.size()+1) {
            return p+fix2;
        }
        else {
            return p+fix3;
        }
    }

    return p;


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