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 "prison.h"
#include "bits/stdc++.h"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
std::vector<std::vector<int>> devise_strategy(int N)
{
int d = 1;
while (1 << (d + 1) <= N)
++d;
vvi ans(2 * d + 2, vi(N + 1));
vi bagSmaller = {-1, -2};
int bag = 0;
ans[0][0] = bag;
for (int i = 1; i <= N; ++i)
ans[0][i] = ((1 << d) & i) ? 2 * d + 1 : 2 * d;
for (int j = d; j > 0; --j)
{
bag ^= 1;
ans[2 * j][0] = ans[2 * j + 1][0] = bag;
for (int i = 1; i <= N; ++i)
if (i & (1 << j))
{
if (j > 1)
ans[2 * j + 1][i] = 2 * (j - 1) + ((i >> (j - 1)) & 1);
else
ans[2 * j + 1][i] = bagSmaller[bag ^ (i & 1)];
ans[2 * j][i] = bagSmaller[bag ^ 1];
}
else
{
ans[2 * j + 1][i] = bagSmaller[bag];
if (j > 1)
ans[2 * j][i] = 2 * (j - 1) + ((i >> (j - 1)) & 1);
else
ans[2 * j][i] = bagSmaller[bag ^ (i & 1)];
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |