이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prison.h"
#include<bits/stdc++.h>
using namespace std;
#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define s second
#define f first
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 1e6;
int iss[10][5001];
vector<vector<int>> devise_strategy(int n) {
int pw[8];
pw[0] = 1;
for (int i = 1; i < 8; i++) pw[i] = pw[i - 1] * 3;
vector<pii> lr[8];
lr[7].push_back({1, n});
for (int b = 7; b >= 0; b--) {
for (int i = 1; i <= n; i++) iss[b][i] = -1;
for (auto [l, r]: lr[b]) {
iss[b][l] = 1, iss[b][r] = 2;
vector<int> tl(3, n + 1);
vector<int> tr(3, -1);
for (int i = l + 1; i < r; i++) {
int v = (i / pw[b]) % 3;
tl[v] = min(tl[v], i);
tr[v] = i;
iss[b][i] = 0;
}
if (!b) continue;
for (int i = 0; i < 3; i++) {
if (tr[i] < tl[i]) continue;
lr[b - 1].push_back({tl[i], tr[i]});
}
}
}
vector<int> f(31), g(40);
int j = 0;
for (int i = 0; i <= 21; i++, j++) {
if (j == 1 || j == 3) j++;
f[i] = j;
g[j] = i;
}
vector<vector<int>> ans;
for (int z = 0; z <= 21; z++) {
int x = f[z];
if (!x) {
vector<int> s = {0};
for (int i = 1; i <= n; i++) {
if (i == 1) s.push_back(-1);
else if (i == n) s.push_back(-2);
else {
int v = (i / pw[7]) % 3;
s.push_back(g[7 * 3 + v + 1]);
}
}
ans.push_back(s);
continue;
}
int v = x - 1;
if ((v / 3) & 1) {
vector<int> s = {1};
int b = v / 3, is = v % 3;
for (int i = 1; i <= n; i++) {
int y = (i / pw[b]) % 3;
if (is < y) s.push_back(-1);
else if (is > y) s.push_back(-2);
else {
if (iss[b][i] == 1 || iss[b - 1][i] == 1) {
s.push_back(-2);
continue;
}
if (iss[b][i] || iss[b - 1][i]) {
s.push_back(-1);
continue;
}
y = (i / pw[b - 1]) % 3;
if (b == 1 && y == 0) s.push_back(-2);
else if (b == 1 && y == 2) s.push_back(-1);
else s.push_back(g[(b - 1) * 3 + y + 1]);
}
}
ans.push_back(s);
}else {
vector<int> s = {0};
int b = v / 3, is = v % 3;
for (int i = 1; i <= n; i++) {
int y = (i / pw[b]) % 3;
if (is < y) s.push_back(-2);
else if (is > y) s.push_back(-1);
else {
if (iss[b][i] == 1 || (b && iss[b - 1][i] == 1)) {
s.push_back(-1);
continue;
}
if (iss[b][i] || (b && iss[b - 1][i])) {
s.push_back(-2);
continue;
}
if (b == 0) s.push_back(-1);
else {
y = (i / pw[b - 1]) % 3;
s.push_back(g[(b - 1) * 3 + y + 1]);
}
}
}
ans.push_back(s);
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |