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;
#define N 128
int val[N];
int counter = 1;
set<int> pos[N];
vector<int> ans;
string s;
void init(int id, int l, int r){
if(l == r) return;
int m = (l + r) >> 1;
init(id << 1, l, m);
init(id << 1 | 1, m + 1, r);
val[id] = counter - r + l;
for(int i = 0; i < val[id]; i++)
s[i] = '1';
for(int i = l; i <= r; i++)
s[i] = '1';
for(int i = l; i <= m; i++){
s[i] = '0';
add_element(s);
s[i] = '1';
}
for(int i = l; i <= r; i++)
s[i] = '0';
for(int i = 0; i < val[id]; i++)
s[i] = '0';
counter++;
}
void solve(int id, int l, int r){
if(l == r){
ans[l] = *pos[l].begin();
return;
}
int m = (l + r) >> 1;
for(int i = 0; i < val[id]; i++)
s[ans[i]] = '1';
for(int x : pos[l]){
s[x] = '1';
}
set<int> ree;
for(int x : pos[l]){
s[x] = '0';
if(check_element(s))
ree.insert(x);
s[x] = '1';
}
for(int i = l; i <= m; i++)
pos[i] = ree;
for(int i = m + 1; i <= r; i++)
for(int x : ree)
pos[i].erase(x);
for(int x : pos[l])
s[x] = '0';
for(int x : pos[r])
s[x] = '0';
for(int i = 0; i < val[id]; i++)
s[ans[i]] = '0';
solve(id << 1, l, m);
solve(id << 1 | 1, m + 1, r);
}
vector<int> res;
vector<int> restore_permutation(int n, int w, int r) {
for(int i = 0; i < n; i++)
s.push_back('0');
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
pos[i].insert(j);
ans.resize(n);
res.resize(n);
init(1, 0, n - 1);
compile_set();
solve(1, 0, n - 1);
for(int i = 0; i < n; i++)
res[ans[i]] = i;
return res;
}
# | 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... |