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 "messy.h"
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " " << x << endl
#define _ << " " <<
void add_elements(int lo, int hi, int n) {
if (lo + 1 == hi) return;
string s(n, '0');
for (int i = 0; i < n; ++i)
if (i < lo || i >= hi) s[i] = '1';
for (int i = lo; i < (lo + hi) / 2; ++i) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
add_elements(lo, (lo + hi) / 2, n);
add_elements((lo + hi) / 2, hi, n);
}
void solve(int lo, int hi, int n, const set<int> &target, vector<int> &p) {
assert(hi - lo == (int) target.size());
if (lo + 1 == hi) {
p[*target.begin()] = lo;
return;
}
string s(n, '0');
for (int i = 0; i < n; ++i)
if (target.find(i) == target.end())
s[i] = '1';
set<int> a, b;
for (int x : target) {
s[x] = '1';
bool flag = check_element(s);
s[x] = '0';
if (flag) a.insert(x); else b.insert(x);
}
assert(a.size() == b.size());
solve(lo, (lo + hi) / 2, n, a, p);
solve((lo + hi) / 2, hi, n, b, p);
}
vector<int> restore_permutation(int n, int w, int r) {
add_elements(0, n, n);
compile_set();
vector<int> ret(n);
set<int> dest;
for (int i = 0; i < n; ++i) dest.insert(i);
solve(0, n, n, dest, ret);
return ret;
}
# | 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... |