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;
std::vector<std::vector<int>> devise_strategy (int n) {
vector < vector < int > > ans (25, vector < int > (n + 1));
vector < int > mp (25);
for (int i = 0, j = 0; i < 25; ++i)
{
if (i == 1 || i == 3) continue;
mp[i] = j++;
}
mp[1] = mp[3] = -1;
for (int i = 0; i < 8; ++i)
for (int j = 0; j < 3; ++j)
{
if (mp[i * 3 + j + 1] == -1) continue;
int k = i * 3 + j + 1;
ans[k][0] = i % 2;
for (int m = 1; m <= n; ++m)
{
int p = m;
for (int q = 0; q < i; ++q) p /= 3;
p %= 3;
if (p < j) ans[k][m] = -1 - (i % 2);
else if (p > j) ans[k][m] = -2 + (i % 2);
else
{
if (i == 0) continue;
p = m;
for (int q = 0; q < i - 1; ++q) p /= 3;
p %= 3;
if (i == 1 && p != 1)
{
if (p == 2) ans[k][m] = -2 + (i % 2);
else ans[k][m] = -1 - (i % 2);
}
else ans[k][m] = mp[(i - 1) * 3 + p + 1];
}
}
}
ans[0][0] = 8 % 2;
for (int m = 1; m <= n; ++m)
{
int p = m;
for (int q = 0; q < 7; ++q) p /= 3;
p %= 3;
ans[0][m] = mp[7 * 3 + p + 1];
}
ans.erase (ans.begin () + 3);
ans.erase (ans.begin () + 1);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |