# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
924728 | boris_mihov | Monster Game (JOI21_monster) | C++17 | 52 ms | 1112 KiB |
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 "monster.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <random>
typedef long long llong;
const int MAXN = 1000 + 10;
const int INF = 1e9;
std::mt19937 rng(69420);
void rec(std::vector <int> &v)
{
if (v.size() <= 1)
{
return;
}
if (v.size() == 2)
{
if (!Query(v[0], v[1])) std::swap(v[0], v[1]);
return;
}
int idx = rng() % v.size();
std::swap(v[0], v[idx]);
int pivot = v[0];
std::vector <int> left, right;
for (int i = 1 ; i < v.size() ; ++i)
{
if (!Query(pivot, v[i])) left.push_back(v[i]);
else right.push_back(v[i]);
}
left.push_back(pivot);
rec(left);
rec(right);
v.clear();
for (const int &i : left)
{
v.push_back(i);
}
for (const int &i : right)
{
v.push_back(i);
}
}
std::vector <int> res;
std::vector <int> Solve(int n)
{
std::vector <int> v(n);
std::iota(v.begin(), v.end(), 0);
rec(v); res.resize(n);
for (int i = 0 ; i < n ; ++i)
{
res[v[i]] = i;
}
return res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |