# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
628761 | tutis | Prisoner Challenge (IOI22_prison) | C++17 | 6 ms | 596 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 "prison.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<std::vector<int>> devise_strategy(int N) {
vector<vector<int>>ret;
vector<pair<int, int>>S = {{1, N}};
vector<pair<int, int>>S_;
bool fst = true;
while (!S.empty())
{
S_ = {};
int x = (int)ret.size();
int mx = 0;
ret.push_back(vector<int>(N + 1, 0));
if (fst == false)
{
for (int i = 0; i < (int)S.size(); i++)
{
int &lo = S[i].first;
int &hi = S[i].second;
lo++;
hi--;
ret[x][lo] = -1;
ret[x][hi] = -2;
if (lo <= hi)
S_.push_back({lo, hi});
}
S = S_;
S_ = {};
}
for (int i = 0; i < (int)S.size(); i++)
{
int lo = S[i].first;
int hi = S[i].second;
lo++;
hi--;
mx = max(mx, hi - lo + 1);
}
if (mx >= 7)
{
for (int t = 0; t < 4; t++)
ret.push_back(vector<int>(N + 1, 0));
for (int t = 0; t < 4; t++)
ret[x + 1 + t][0] = 1;
vector<int>&v = ret[x];
v[0] = 0;
for (int i = 0; i < (int)S.size(); i++)
{
int lo = S[i].first;
int hi = S[i].second;
v[lo] = -1;
v[hi] = -2;
lo++;
hi--;
int sz = hi - lo + 1;
if (sz >= 1)
{
int k = (sz + 3) / 4;
k = max(k, 2);
for (int t = 0; t < 4; t++)
{
int l = lo + t * k;
int r = lo + (t + 1) * k - 1;
r = min(r, hi);
if (l <= r)
{
for (int i = l; i <= r; i++)
{
ret[(x + 1) + t][i] = x + 5;
v[i] = x + 1 + t;
}
for (int i = lo - 1; i <= l; i++)
{
ret[(x + 1) + t][i] = -2;
}
for (int i = r; i <= hi + 1; i++)
{
ret[(x + 1) + t][i] = -1;
}
if (r - l + 1 > 2)
{
S_.push_back({l, r});
}
}
}
}
}
S = S_;
}
else if (mx >= 5)
{
for (int t = 0; t < 3; t++)
ret.push_back(vector<int>(N + 1, 0));
for (int t = 0; t < 3; t++)
ret[x + 1 + t][0] = 1;
vector<int>&v = ret[x];
v[0] = 0;
for (int i = 0; i < (int)S.size(); i++)
{
int lo = S[i].first;
int hi = S[i].second;
v[lo] = -1;
v[hi] = -2;
lo++;
hi--;
int sz = hi - lo + 1;
if (sz >= 1)
{
int k = (sz + 2) / 3;
k = max(k, 2);
for (int t = 0; t < 3; t++)
{
int l = lo + t * k;
int r = lo + (t + 1) * k - 1;
r = min(r, hi);
if (l <= r)
{
for (int i = l; i <= r; i++)
{
ret[(x + 1) + t][i] = x + 4;
v[i] = x + 1 + t;
}
for (int i = lo - 1; i <= l; i++)
{
ret[(x + 1) + t][i] = -2;
}
for (int i = r; i <= hi + 1; i++)
{
ret[(x + 1) + t][i] = -1;
}
if (r - l + 1 > 2)
{
S_.push_back({l, r});
}
}
}
}
}
S = S_;
}
else if (mx >= 3)
{
for (int t = 0; t < 2; t++)
ret.push_back(vector<int>(N + 1, 0));
for (int t = 0; t < 2; t++)
ret[x + 1 + t][0] = 1;
vector<int>&v = ret[x];
v[0] = 0;
for (int i = 0; i < (int)S.size(); i++)
{
int lo = S[i].first;
int hi = S[i].second;
v[lo] = -1;
v[hi] = -2;
lo++;
hi--;
int sz = hi - lo + 1;
if (sz >= 1)
{
int k = (sz + 1) / 2;
k = max(k, 2);
for (int t = 0; t < 2; t++)
{
int l = lo + t * k;
int r = lo + (t + 1) * k - 1;
r = min(r, hi);
if (l <= r)
{
for (int i = l; i <= r; i++)
{
ret[(x + 1) + t][i] = x + 3;
v[i] = x + 1 + t;
}
for (int i = lo - 1; i <= l; i++)
{
ret[(x + 1) + t][i] = -2;
}
for (int i = r; i <= hi + 1; i++)
{
ret[(x + 1) + t][i] = -1;
}
if (r - l + 1 > 2)
{
S_.push_back({l, r});
}
}
}
}
}
S = S_;
}
else if (mx >= 1)
{
for (int t = 0; t < 1; t++)
ret.push_back(vector<int>(N + 1, 0));
for (int t = 0; t < 1; t++)
ret[x + 1 + t][0] = 1;
vector<int>&v = ret[x];
v[0] = 0;
for (int i = 0; i < (int)S.size(); i++)
{
int lo = S[i].first;
int hi = S[i].second;
v[lo] = -1;
v[hi] = -2;
lo++;
hi--;
int sz = hi - lo + 1;
if (sz >= 1)
{
int k = (sz + 1) / 1;
k = max(k, 2);
for (int t = 0; t < 1; t++)
{
int l = lo + t * k;
int r = lo + (t + 1) * k - 1;
r = min(r, hi);
if (l <= r)
{
for (int i = l; i <= r; i++)
{
ret[(x + 1) + t][i] = x + 2;
v[i] = x + 1 + t;
}
for (int i = lo - 1; i <= l; i++)
{
ret[(x + 1) + t][i] = -2;
}
for (int i = r; i <= hi + 1; i++)
{
ret[(x + 1) + t][i] = -1;
}
if (r - l + 1 > 2)
{
S_.push_back({l, r});
}
}
}
}
}
S = S_;
}
else
{
vector<int>&v = ret[x];
v[0] = 0;
for (int i = 0; i < (int)S.size(); i++)
{
int lo = S[i].first;
int hi = S[i].second;
v[lo] = -1;
v[hi] = -2;
}
S = S_;
}
int x1 = ret.size();
fst = false;
//cout << mx << " " << x1 - x << endl;
}
int mx = (int)ret.size() - 1;
for (vector<int> &i : ret)
for (int &j : i)
j = min(j, mx);
return ret;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |