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