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"
using namespace std;
string now;
vector<int> per;
vector<int> ans;
void dnc1(int s, int e) {
if (s == e) return;
int m = (s + e) / 2;
for (int i = m + 1; i <= e; ++i) {
now[i] = '1';
add_element(now);
now[i] = '0';
}
for (int i = m + 1; i <= e; ++i) now[i] = '1';
dnc1(s, m);
for (int i = m + 1; i <= e; ++i) now[i] = '0';
now[s] = '1';
dnc1(m + 1, e);
now[s] = '0';
}
vector<int> group[1024];
void dnc2(int idx, int s, int e) {
if (s == e) {
per[s] = group[idx].back();
return;
}
int m = (s + e) / 2;
for (int i : group[idx]) {
now[i] = '1';
if (check_element(now)) group[idx * 2 + 1].push_back(i);
else group[idx * 2].push_back(i);
now[i] = '0';
}
for (int i : group[idx * 2 + 1]) now[i] = '1';
dnc2(idx * 2, s, m);
for (int i : group[idx * 2 + 1]) now[i] = '0';
now[per[s]] = '1';
dnc2(idx * 2 + 1, m + 1, e);
now[per[s]] = '0';
}
std::vector<int> restore_permutation(int n, int w, int r) {
per.resize(n);
ans.resize(n);
now.resize(n, '0');
dnc1(0, n - 1);
compile_set();
group[1].resize(n);
for (int i = 0; i < n; ++i) group[1][i] = i;
dnc2(1, 0, n - 1);
for (int i = 0; i < n; ++i) ans[per[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... |