# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
628761 | tutis | 죄수들의 도전 (IOI22_prison) | C++17 | 6 ms | 596 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |