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>
#include "messy.h"
using namespace std;
vector<int> restore_permutation(int n, int w, int r) {
vector<int> p(n, -1);
function<void(int, int, string)> init = [&](int l, int r, string b) {
if (l + 1 == r) {
return;
}
int mid = (l + r) >> 1;
for (int i = mid; i < r; ++i) {
b[i] = '1';
add_element(b);
b[i] = '0';
}
for (int i = mid; i < r; ++i) {
b[i] = '1';
}
init(l, mid, b);
for (int i = mid; i < r; ++i) {
b[i] = '0';
b[l + (i - mid)] = '1';
}
init(mid, r, b);
};
init(0, n, string(n, '0'));
compile_set();
function<void(vector<int>, vector<int>, int, int)> solve = [&](vector<int> a, vector<int> sure, int ans, int dep) {
const int sz = a.size();
if (sz == 1) {
p[a[0]] = ans;
return;
}
vector<int> on, off;
for (int i: a) {
string s(n, '0');
for (int x: sure) {
s[x] = '1';
}
s[i] = '1';
if (check_element(s)) {
on.push_back(i);
} else {
off.push_back(i);
}
}
sure.insert(sure.end(), on.begin(), on.end());
solve(off, sure, ans, dep - 1);
sure.resize(sure.size() - on.size());
sure.insert(sure.end(), off.begin(), off.end());
solve(on, sure, ans + (1 << dep), dep - 1);
};
vector<int> a(n);
iota(a.begin(), a.end(), 0);
solve(a, {}, 0, __lg(n) - 1);
return p;
}
# | 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... |