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>
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
int n;
vector<vector<int> > ans;
vector<vector<int>> devise_strategy(int N) {
const int g[]={2,8,26,80,242,728,1458,2918,5838};
int w=0;
for(;;w++){
if(g[w]>=N){
n=g[w];
break;
}
}
w--;
vector<int> pz(n+1);
pz[0]=0;
for(int i=1;i<=n;i++){
int s=(i-1)%g[w+1];
if(s==0){
pz[i]=-1;
}
else if(s==n-1){
pz[i]=-2;
}
else{
pz[i]=(s-1)/g[w]+1;
}
}
ans.push_back(pz);
int q=1+(g[w+1]-2)/g[w],l=2;
int fl=1;
vector<int> vis(n+1);
vis[1]=-1;
vis[n]=1;
for(w--;w>=-1;w--){
int p=(g[w+2]-2)/g[w+1];
vector<vector<int> > pp(p);
for(int i=0;i<p;i++){
pp[i].resize(n+1);
pp[i][0]=fl;
}
for(int j=1;j<=n;j++){
if(!vis[j]){
for(int i=0;i<p;i++){
int j2=(j-(l))%g[w+2];
//assert(j2>=0);
int s1=j2/g[w+1];
if(s1<i){
pp[i][j]=-1-fl;
}
else if(s1>i){
pp[i][j]=fl-2;
}
else{
int s2=(j2)%g[w+1];
if(s2==0){
pp[i][j]=-1-fl;
vis[j]=-1;
}
else if(s2==g[w+1]-1){
pp[i][j]=fl-2;
vis[j]=1;
}
else{
pp[i][j]=q+(s2-1)/g[w];
}
}
}
}
else{
for(int i=0;i<p;i++){
if(vis[j]==1){
pp[i][j]=fl-2;
}
else{
pp[i][j]=-1-fl;
}
}
}
}
for(auto h:pp){
ans.push_back(h);
}
if(w<0){
break;
}
int s=(g[w+1]-2)/g[w];
q+=s;
fl^=1;
l++;
}
//freopen("err.txt","w",stderr);
for(auto &h:ans){
while(h.size()>(N+1)){
h.pop_back();
}
for(int i=0;i<=n;i++){
cerr << h[i] << " ";
}
cerr << '\n';
}
return ans;
}
Compilation message (stderr)
prison.cpp: In function 'std::vector<std::vector<int> > devise_strategy(int)':
prison.cpp:99:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
99 | while(h.size()>(N+1)){
| ~~~~~~~~^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |