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;
int calc(int a, int x) {
a--;
int r = 4999;
for(int i = 0; i <= x; i++) {
if(a == 0) {
return -1;
}
else if(a == r) {
return 3;
}
r-=2;
r = (r/3);
a--;
if(i == x) {
return a/(r+1);
}
a%=r+1;
}
}
vector<vector<int>> devise_strategy(int n) {
vector<vector<int>> ans(21,vector<int> (n+1));
ans[0][0] = 0;
for(int i = 1; i <= n; i++) {
if(i == 1) {
ans[0][i] = -1;
}
else if(i == n) {
ans[0][i] = -2;
}
else {
ans[0][i] = calc(i,0)+1;
}
}
for(int i = 1; i <= 20; i++) {
int c = (i-1)/3+1;
ans[i][0] = c%2;
for(int j = 1; j <= n; j++) {
if(calc(j,c-1) == (i-1)%3) {
if(calc(j,c) == -1) {
if(c%2) {
ans[i][j] = -2;
}
else {
ans[i][j] = -1;
}
}
else if(calc(j,c) == 3) {
if(c%2) {
ans[i][j] = -1;
}
else {
ans[i][j] = -2;
}
}
else {
ans[i][j] = c*3+calc(j,c)+1;
}
}
else {
if(calc(j,c-1) < (i-1)%3) {
if(c%2) {
ans[i][j] = -2;
}
else {
ans[i][j] = -1;
}
}
else {
if(c%2) {
ans[i][j] = -1;
}
else {
ans[i][j] = -2;
}
}
}
}
}
return ans;
}
Compilation message (stderr)
prison.cpp: In function 'int calc(int, int)':
prison.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
23 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |