#include "prison.h"
#include <bits/stdc++.h>
using namespace std;
const int x = 22;
string toBase3(int n)
{
string s = "";
while(n != 0)
{
s = to_string(n%3) + s;
n /= 3;
}
while(s.length() < 8)
{
s = "0" + s;
}
return s;
}
vector<vector<int>> devise_strategy(int N)
{
vector<vector<int>> res(x+1);
for(int i = 0; i < x+1; i++)
{
res[i] = vector<int>(N+1);
res[i][0] = ((i+2) / 3) % 2;
if(i == 0)
{
for(int j = 1; j < N+1; j++)
{
string base3 = toBase3(j);
res[i][j] = base3[0] - '0' + 1;
//cout << res[i][j] << " ";
}
}
else if(i == x)
{
for(int j = 1; j < N+1; j++)
{
string base3 = toBase3(j);
int thisnumber = -1 - res[i][0];
if(base3[7] == '0') res[i][j] = thisnumber;
if(base3[7] == '2') res[i][j] = (-3 - thisnumber);
}
}
else
{
for(int j = 1; j < N+1; j++)
{
string base3 = toBase3(j);
int lastdigit = (i-1)%3;
int numdigit = (i+2)/3;
int digit = base3[numdigit-1] - '0';
int thisdigit = base3[numdigit] - '0';
int thisnumber = -1 - res[i][0];
if(digit != lastdigit)
{
res[i][j] = (digit < lastdigit)? thisnumber : (-3 - thisnumber);
//cout << res[i][j] << " ";
}
else
{
if(numdigit == 7)
{
if(thisdigit == 0) res[i][j] = thisnumber;
else if(thisdigit == 2) res[i][j] = (-3 - thisnumber);
else res[i][j] = x;
}
else
{
res[i][j] = base3[(i+2)/3] - '0' + ((i+2)/3)*3 + 1;
}
//cout << res[i][j] << " ";
}
}
}
//cout << "\n";
}
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |