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 pb push_back
int n;
vector<int> ans_r;
string ts(int k) {
string s = "";
for (int i = 0; i < n; i++) {
s.pb(!!(k & (1 << i)) + '0');
}
return s;
}
void dnc(int in_l, int in_r, vector<int> out) {
if (in_l == in_r) {
ans_r[in_l] = out[0];
return;
}
vector<int> fh_out, sh_out;
int cur = 0;
for (int i = 0; i < n; i++) {
if (!binary_search(out.begin(), out.end(), i)) cur |= (1 << i);
}
for (int i = 0; i < (int)out.size(); i++) {
cur ^= (1 << out[i]);
if (check_element(ts(cur))) {
fh_out.pb(out[i]);
} else {
sh_out.pb(out[i]);
}
cur ^= (1 << out[i]);
}
int in_m = (in_l + in_r) / 2;
dnc(in_l, in_m, fh_out);
dnc(in_m + 1, in_r, sh_out);
}
vector<int> restore_permutation(int n, int w, int r) {
::n = n;
for (int i = 1; (1 << i) <= n; i++) {
for (int j = 0; j < n; j += (1 << i)) {
int base = ((1 << n) - 1);
for (int k = j; k < j + (1 << i); k++) {
base ^= (1 << k);
}
for (int k = j; k < j + (1 << (i - 1)); k++) {
base ^= (1 << k);
add_element(ts(base));
base ^= (1 << k);
}
}
}
compile_set();
vector<int> all;
for (int i = 0; i < n; i++) all.pb(i);
ans_r.resize(n);
dnc(0, n - 1, all);
vector<int> ans(n);
for (int i = 0; i < n; i++) {
ans[ans_r[i]] = i;
}
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... |