이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prison.h"
#include <vector>
#include <algorithm>
using namespace std;
constexpr int N = 5005;
vector<vector<int>> a;
int n, maxbit;
bool ck[N];
#define bit(i, x) (((x) >> (i)) & 1)
void Recursive(int v)
{
if (ck[v])
return;
ck[v] = 1;
if (v == 0)
{
a[v][0] = 0;
for (int i = 1; i <= n; ++i)
a[v][i] = maxbit - 1 + (bit(maxbit, i) * maxbit) + 1;
for (int i = 1; i <= n; ++i)
if (a[v][i] > 0)
Recursive(a[v][i]);
return;
}
--v;
int number, state;
if (v >= maxbit)
{
state = 1;
number = v - maxbit;
}
else
{
state = 0;
number = v;
}
++number;
++v;
if ((number & 1) != (maxbit & 1))
{
a[v][0] = 1;
for (int i = 1; i <= n; ++i)
if (bit(number, i) < state)
a[v][i] = -2;
else if (bit(number, i) > state)
a[v][i] = -1;
else
{
if (number == 1)
{
if (bit(0, i))
a[v][i] = -1;
else
a[v][i] = -2;
}
a[v][i] = number - 1 + (bit(number - 1, i) * maxbit);
}
for (int i = 1; i <= n; ++i)
if (a[v][i] > 0)
Recursive(a[v][i]);
}
else
{
a[v][0] = 0;
for (int i = 1; i <= n; ++i)
if (bit(number, i) < state)
a[v][i] = -1;
else if (bit(number, i) > state)
a[v][i] = -2;
else
{
if (number == 1)
{
if (bit(0, i))
a[v][i] = -2;
else
a[v][i] = -1;
}
else
a[v][i] = number - 1 + (bit(number - 1, i) * maxbit);
}
for (int i = 1; i <= n; ++i)
if (a[v][i] > 0)
Recursive(a[v][i]);
}
}
std::vector<std::vector<int>> devise_strategy(int m)
{
n = m;
maxbit = __lg(n);
a.resize(5000, vector<int>(n + 1, 0));
Recursive(0);
while (!ck[a.size() - 1])
a.pop_back();
return a;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |