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 <bits/stdc++.h>
using namespace std;
// 3 ** 6 * 7 > 5000
const int BASE = 3;
const int POWER = 6;
const int REMAIN = 7;
vector<vector<int>> devise_strategy(int n) {
vector<vector<int>> ans;
vector<vector<int>> digits(729);
for (int i = 0; i < 729; i++)
{
for (int j = 0, x = i; j < POWER; j++)
{
digits[i].push_back(x % BASE);
x /= BASE;
}
reverse(begin(digits[i]), end(digits[i]));
}
// 0
{
vector<int> a = {0};
for (int j = 0; j < n; j++)
a.push_back(digits[j / REMAIN][0] + 1);
ans.push_back(a);
}
// [1, 18]
for (int i = 0; i < POWER; i++)
for (int x = 0; x < BASE; x++)
{
int otherBag = i % 2, curBag = otherBag ^ 1;
vector<int> a = {curBag};
for (int j = 0; j < n; j++)
{
auto curDigits = digits[j / REMAIN];
if (curDigits[i] < x) a.push_back(-curBag - 1);
else if (curDigits[i] > x) a.push_back(-otherBag - 1);
else if (i < POWER - 1) a.push_back((i + 1) * BASE + curDigits[i + 1] + 1);
else // last digit
{
int rem = j % REMAIN;
if (rem == 0) a.push_back(-curBag - 1);
else if (rem == 6) a.push_back(-otherBag - 1);
else if (rem <= 2) a.push_back(19); // 1, 2
else if (rem <= 4) a.push_back(20); // 3, 4
else a.push_back(21); // 5
}
}
ans.push_back(a);
}
// [19, 21]
for (int i : {19, 20, 21})
{
int otherBag = 0, curBag = 1;
vector<int> a = {1};
for (int j = 0; j < n; j++)
{
int rem = j % REMAIN;
if (rem <= 1) a.push_back(-curBag - 1);
else if (rem >= 5) a.push_back(-otherBag - 1);
else if (rem <= 3) a.push_back(-(i == 19 ? otherBag : curBag) - 1);
else a.push_back(-(i == 21 ? curBag : otherBag) - 1);
}
ans.push_back(a);
}
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... |