# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
760923 | midi | Combo (IOI18_combo) | C++14 | 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vcll;
typedef vector<int> vci;
typedef pair<ll, ll> prll;
typedef pair<int, int> prii;
#define f0r(i, a, n) for (i = a; i < n; i++)
#define f1r(i, a, n) for (i = a; i <= n; i++)
#define r0f(i, n, a) for (i = n; i > a; i--)
#define r1f(i, n, a) for (i = n; i >= a; i--)
#define pb push_back
char tar[] = {'A', 'B', 'X', 'Y', 'A', 'B', 'X'};
char A, B, C, D;
void init(char start)
{
ll n = sizeof(tar);
ll i;
f0r(i, 0, n)
if (tar[i] == start) break;
A = tar[i++];
B = tar[i++];
C = tar[i++];
D = tar[i++];
}
void paste(string &from, string &to)
{
for (auto const &c : from)
to.pb(c);
}
string guess_sequence(int N)
{
ll n = N;
string builder;
ll res = press("AB");
char start;
if (res)
{
res = press("A");
if (res) start = 'A';
else start = 'B';
}
else
{
res = press("X");
if (res) start = 'X';
else start = 'Y';
}
init(start);
builder.pb(A);
// first char, done
ll i = 0;
string pusher, adder;
f0r(i, 1, n-1)
{
paste(builder, pusher);
adder.pb(B);
paste(adder, pusher);
adder.clear();
paste(builder, pusher);
adder.pb(C); adder.pb(B);
paste(adder, pusher);
adder.clear();
paste(builder, pusher);
adder.pb(C); adder.pb(C);
paste(adder, pusher);
adder.clear();
paste(builder, pusher);
adder.pb(C); adder.pb(D);
paste(adder, pusher);
adder.clear();
res = press(pusher);
pusher.clear();
if (res == i) builder.pb(D);
else if (res == i + 1) builder.pb(B);
else builder.pb(C);
}
// all the middles, done
builder.pb(B);
res = press(builder);
if (res != n)
{
builder.back() = C;
res = press(builder);
if (res != n)
{
builder.back() = D;
}
}
return builder;
// last char
}