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 <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;
const int k = 21;
vector<vector<int>> s;
void fill(int vr, int l, int r) // na ktorom vrchole sme, vrecko ktore sme vyskusali naposledy, interval v ktorom su obe tie hodnoty
{
if (r <= l) return;
s[vr][l] = -1 - s[vr][0];
s[vr][r] = -2 + s[vr][0];
if (l + 1 == r) return;
int nx = vr;
while (s[vr][0] == s[nx][0]) nx++;
int d = (r - l + 1) / 3;
vector<int> v;
for (int i = 0; i < 4; i++)
{
v.push_back(min(l + 1 + i * d, r));
if (v.back() == r) break;
}
if (nx == 19)
{
v = { l + 1, min(l + 3, r), r };
if (v[1] == r) v.pop_back();
}
for (int i = 0; i + 1 < v.size(); i++)
{
int li = v[i], ri = v[i + 1] - 1;
for (int j = li; j <= ri; j++) s[vr][j] = nx + i;
for (int j = l; j < li; j++) s[nx + i][j] = -1 - s[nx + i][0];
for (int j = ri + 1; j <= r; j++) s[nx + i][j] = -2 + s[nx + i][0];
fill(nx + i, li, ri);
}
}
vector<vector<int>> devise_strategy(int n)
{
s.assign(k, vector<int>(n + 1, 0));
s[0][0] = 0;
for (int i = 1; i < k; i++) s[i][0] = 1 - s[max(0, i - 3)][0];
fill(0, 1, n);
return s;
}
Compilation message (stderr)
prison.cpp: In function 'void fill(int, int, int)':
prison.cpp:42:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i + 1 < v.size(); i++)
| ~~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |