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;
string s;
vector<int> ans;
int n;
void rec1(int l, int r) {
if (l == r) return;
int m = (l + r) / 2;
for (int i = 0; i < n; i++) s[i] = '1';
for (int i = l; i <= r; i++) s[i] = '0';
for (int i = l; i <= m; i++) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
rec1(l, m);
rec1(m + 1, r);
}
void rec2(int l, int r, vector<int> v) {
if (l == r) {
ans[v[0]] = l;
return;
}
int m = (l + r) / 2;
for (int i = 0; i < n; i++) s[i] = '1';
for (int x : v) s[x] = '0';
vector<int> vl, vr;
for (int x : v) {
s[x] = '1';
if (check_element(s)) vl.push_back(x);
else vr.push_back(x);
s[x] = '0';
}
rec2(l, m, vl);
rec2(m + 1, r, vr);
}
std::vector<int> restore_permutation(int n1, int w, int r) {
n = n1;
s.resize(n);
ans.resize(n);
rec1(0, n - 1);
compile_set();
vector<int> v;
for (int i = 0; i < n; i++) v.push_back(i);
rec2(0, n - 1, v);
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... |