#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 ptr = 0 ; ptr < next.size() - 1 ; ++ptr)
{
char symbol = next[ptr];
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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |