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(vector<int> in, vector<int> out) {
	if ((int)in.size() == 1) {
		ans_r[in[0]] = out[0];
		return;
	}
	vector<int> fh_in, sh_in, 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]);
	}
	for (int i = 0; i < (int)in.size(); i++) {
		if (i < (int)in.size() / 2) {
			fh_in.pb(in[i]);
		} else {
			sh_in.pb(in[i]);
		}
	}
	dnc(fh_in, fh_out);
	dnc(sh_in, 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(all, 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... |