Submission #778848

#TimeUsernameProblemLanguageResultExecution timeMemory
778848Durza42콤보 (IOI18_combo)C++14
100 / 100
23 ms588 KiB
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include "combo.h"

#define endl '\n'
#define ll long long int

using namespace std;


constexpr array<char, 4> LETTERS { 'A', 'B', 'X', 'Y' };

string guess_sequence(int N)
{
    string S = ".";

    if(press("AB") > 0)
    {
        if(press("A") > 0)
            S[0] = 'A';
        else
            S[0] = 'B';
    }
    else
    {
        if(press("X") > 0)
            S[0] = 'X';
        else
            S[0] = 'Y';
    }

    if(N <= 1)
        return S;

    vector<string> l;
    for(int i = 0 ; i < int(LETTERS.size()) ; ++i)
    {
        if(LETTERS[i] == S[0])
            continue;
        l.push_back(".");
        l.back() = LETTERS[i];
    }


    for(int i = 1 ; i < N - 1 ; ++i)
    {
        string request =
            S + l[0] + l[0]
          + S + l[0] + l[1]
          + S + l[0] + l[2]
          + S + l[1];

//        cout << '(' << S << ')';
        int p = press(request);

        if(p == int(S.length()) + 0)
            S += l[2];
        if(p == int(S.length()) + 1)
            S += l[1];
        if(p == int(S.length()) + 2)
            S += l[0];
//        else
//            press("error");
    }

    if(press(S + l[0]) > int(S.length()))
    {
        S += l[0];
    }
    else
    {
        if(press(S + l[1]) > int(S.length()))
            S += l[1];
        else
            S += l[2];
    }

    return S;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...