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;
vector <int> p;
int n;
void build(int l, int r){
if (l == r) return;
int m = (l + r)/2;
string s;
for (int i = 0; i < n; i++){
if (i >= l && i <= r) s += "0";
else s += "1";
}
for (int i = l; i <= m; i++){
string st = s;
st[i] = '1';
add_element(st);
}
build(l, m);
build(m + 1, r);
}
void solve(int l, int r, vector<int> curr, vector<int> other){
if (l == r){
p[l] = curr[0];
return;
}
int m = (l + r)/2;
string s;
for (int i = 0; i < n; i++) s += "0";
for (auto x : other) s[x] = '1';
vector <int> n1, n2;
for (auto x : curr){
string st = s;
st[x] = '1';
if (check_element(st)){
n1.push_back(x);
} else {
n2.push_back(x);
}
}
vector <int> o1 = other;
for (auto x : n2) o1.push_back(x);
solve(l, m, n1, o1);
vector <int> o2 = other;
for (auto x : n1) o2.push_back(x);
solve(m + 1, r, n2, o2);
}
vector<int> restore_permutation(int m, int w, int r) {
// add_element("0");
// compile_set();
// check_element("0");
// return std::vector<int>();
n = m;
p.resize(n);
build(0, n - 1);
compile_set();
vector <int> curr;
for (int i = 0; i < n; i++) curr.push_back(i);
vector <int> other;
solve(0, n - 1, curr, other);
vector <int> inv(n);
for (int i = 0; i < n; i++) inv[p[i]] = i;
return inv;
}
# | 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... |