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>
#include <vector>
using namespace std;
template <class T> using v = vector<T>;
v<v<int>> ans;
void construct(int i, int l, int r, int cur) {
if (l == r) {
return;
}
int m = (l + r) / 2;
for (int j = l; j <= m; j++) {
ans[i][j] = (i + 1) / 2 + 1;
}
for (int j = m + 1; j <= r; j++) {
ans[i][j] = (i + 1) / 2 + 2;
}
construct((i + 1) / 2 + 1, l, m, 1 - cur);
for (int j = m + 1; j <= r; j++) {
ans[(i + 1) / 2 + 1][j] = -(1 - cur) - 1;
}
construct((i + 1) / 2 + 2, m + 1, r, 1 - cur);
for (int j = l; j <= m; j++) {
ans[(i + 1) / 2 + 2][j] = -cur - 1;
}
}
v<v<int>> devise_strategy(int N) {
ans.assign(__lg(2 * N) * 2 + 1, v<int>(N + 1));
for (int i = 0; i < ans.size(); i++) {
ans[i][0] = ((i + 1) / 2) & 1;
for (int j = 1; j <= N; j++) {
ans[i][j] = -ans[i][0] - 1;
}
}
construct(0, 1, N, 1);
return ans;
}
Compilation message (stderr)
prison.cpp: In function 'v<std::vector<int> > devise_strategy(int)':
prison.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 0; i < ans.size(); i++) {
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |