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;
#define sz(x) (int)x.size()
#define pb push_back
int ii = -1;
vector<vector<int>> a;
vector<int> dp, pp;
int rec(int p, int l1, int r1, int l2, int r2, int b) {
int idx = ++ii;
a[idx][0] = p;
for(int i = l1; i <= l2; ++i) a[idx][i] = (!p ? -1 : -2);
for(int i = r2; i <= r1; ++i) a[idx][i] = (!p ? -2 : -1);
int l = l1 + 1, r = r1 - 1;
if(!b) return idx;
int jump = dp[b - pp[b]];
for(int i = l; i < r; i += jump) {
int child = rec(p ^ 1, l2, r2, i, i + jump - 1, b - pp[b]);
for(int j = i; j < i + jump; ++j) a[idx][j] = child;
}
return idx;
}
std::vector<std::vector<int>> devise_strategy(int N) {
dp.push_back(2); pp.push_back(1);
while(dp.back() < N) {
int sz = sz(dp);
dp.push_back(0); pp.push_back(0);
for(int i = 1; i <= sz; ++i) {
if(i * dp[sz - i] + 2 > dp.back()) {
dp.back() = i * dp[sz - i] + 2;
pp.back() = i;
}
}
}
int m = sz(dp);
a.assign(m, vector<int>(dp.back() + 1));
rec(0, 1, dp.back(), 1, dp.back(), m - 1);
for(int i = 0; i < m; ++i) while(sz(a[i]) > N + 1) a[i].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... |