# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
839613 | sleepntsheep | Combo (IOI18_combo) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "combo.h"
#include <string>
#include <vector>
using namespace std;
#define BUT "ABXY"
string guess_sequence(int N)
{
string ans;
int j = 0;
vector<int> non(2005, 0);
for (int i = 0; i < 4; ++i)
{
if (i == 3)
ans[0] = 'Y', ++j;
else
{
ans.resize(2);
ans[0] = BUT[i];
ans[1] = 'A';
int k = press(ans);
if (k == 1) ++j, non[1] |= 1;
if (k == 2) j += 2;
if (k >= 1) break;
}
}
for (int i = j; i < N - 1;)
{
int nxt = i + 1;
for (int j = 0; j < 4; j++)
{
if (j == 3)
ans[i++] = 'Y';
else
{
if (non[i] & (1 << j)) continue;
ans.resize(i+2);
ans[i] = BUT[j];
ans[i+1] = 'A';
int k = press(ans);
if (k == i + 1) non[i+1] |= 1;
if (k == i + 2) { nxt = i + 2; ans[i+1] = 'A'; }
if (k >= i + 1) break;
}
}
i = nxt;
}
for (int j = 0; j < 4; j++)
{
if (j == 3)
ans[i++] = 'Y';
else
{
if (non[N-1] & (1 << j)) continue;
ans.resize(N);
ans[N-1] = BUT[j];
int k = press(ans);
if (k == N) break;
}
}
ans.resize(N);
return ans;
}