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