Submission #1305157

#TimeUsernameProblemLanguageResultExecution timeMemory
1305157kaloyan콤보 (IOI18_combo)C++20
0 / 100
1 ms332 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cassert>

using namespace std;

int press(string p);

void set(string &str, char c, int size)
{
    str.resize(size);

    for(int i = 0 ; i < size ; ++i)
    {
        str[i] = c;
    }
}

string guess_sequence(int N)
{
    string str, res;

    set(str, '0', 4 * N);
    set(res, '0', N);

    char head = '0';
    for(char symbol : {'A', 'B', 'X'})
    {
        set(str, symbol, 4 * N);
        
        if(press(str) == 1)
        {
            head = symbol;
            break;
        }
    }

    if(head == '0')
    {
        head = 'Y';
    }

    std::vector<char> next;
    
    for(char symbol : {'A', 'B', 'X', 'Y'})
    {
        if(symbol == head)
        {
            continue;
        }

        next.push_back(symbol);
    }

    res[0] = head;
    for(int i = 1 ; i < N ; ++i)
    {
        set(str, '0', 4 * N);
        for(int i = 0 ; i < next.size() - 1 ; ++i)
        {
            char symbol = next[i];

            for(int j = 0 ; j <= i - 1 ; ++j)
            {
                str[j] = res[j];
            }

            str[i] = symbol;

            for(int j = i + 1 ; j < 4 * N ; ++j)
            {
                str[j] = head;
            }
            
            if(press(str) == i + 1)
            {
                res[i] = symbol;
                break;
            }
        }

        if(res[i] == '0')
        {
            res[i] = next.back();
        }
    }

    return res;
}


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