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;
vector<int> restore_permutation(int n, int w, int r) {
// add_element("0");
// compile_set();
// check_element("0");
string t;
for(int i = 0; i < n; i++)
t+='0';
queue<pair<int, int>> q;
q.emplace(0, n);
while(!q.empty()) {
int l = q.front().first;
int r = q.front().second;
q.pop();
if(l+1 >= r) continue;
string s = t;
for(int i = 0; i < n; i++)
if(i < l || i >= r)
s[i] = '1';
// cerr << s << endl;
int mid = (l+r)/2;
for(int i = l; i < mid; i++) {
s[i] = '1';
add_element(s);
// cerr << s << endl;
s[i] = '0';
}
q.emplace(l, mid);
q.emplace(mid, r);
}
// cerr << endl << endl;
compile_set();
for(int i = 0; i < n; i++)
t[i] = '1';
map<pair<int, int>, set<int>> pos;
for(int i = 0; i < n; i++)
pos[{0, n}].insert(i);
q.emplace(0, n);
while(!q.empty()) {
int l = q.front().first;
int r = q.front().second;
q.pop();
if(l+1 >= r) continue;
string s = t;
int mid = (l+r)/2;
for(int i = 0; i < n; i++)
if(pos[{l, r}].count(i))
s[i] = '0';
// cerr << s << endl;
for(auto i: pos[{l, r}]) {
s[i] = '1';
if(check_element(s))
pos[{l, mid}].insert(i);
else
pos[{mid, r}].insert(i);
s[i] = '0';
}
q.emplace(l, mid);
q.emplace(mid, r);
}
vector<int> ans(n);
for(int i = 0; i < n; i++)
ans[*pos[{i, i+1}].begin()] = 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... |