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 <vector>
#include "messy.h"
#include <string>
using namespace std;
// [l..r)
void Add(int l, int r, string base)
{
if (l + 1 == r) return;
int mid = (l + r) / 2;
for (int i = l; i < mid; ++i)
{
base[i] = '1';
add_element(base.c_str());
base[i] = '0';
}
// fill one side, recurse in other side
fill(base.begin() + l, base.begin() + mid, '1');
Add(mid, r, base);
fill(base.begin() + l, base.begin() + mid, '0');
fill(base.begin() + mid, base.begin() + r, '1');
Add(l, mid, base);
}
vector<int> ans;
void Solve(int l, int r, vector<int> miss, string base)
{
if (l + 1 == r)
{
ans[miss[0]] = l;
return;
}
vector<int> grL, grR;
for (int x: miss)
{
base[x] = '1';
if (check_element(base.c_str())) grL.push_back(x);
else grR.push_back(x);
base[x] = '0';
}
int mid = (l + r) / 2;
// fill one side, recurse in other side
for (int x: grR) base[x] = '1';
Solve(l, mid, grL, base);
for (int x: grR) base[x] = '0';
for (int x: grL) base[x] = '1';
Solve(mid, r, grR, base);
}
vector<int> restore_permutation(int n, int w, int r) {
Add(0, n, string(n, '0'));
compile_set();
ans.resize(n);
vector<int> all;
for (int i = 0; i < n; ++i) all.push_back(i);
Solve(0, n, all, string(n, '0'));
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |