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 <vector>
#include "messy.h"
using namespace std;
void generate_strings(int n, int l, int r) {
if(l == r) return;
string s;
for(int i = 0; i < n; i++)
s += "0";
for(int i = l; i <= r; i++)
s[i] = '1';
int mid = (l + r) / 2;
for(int i = l; i <= mid; i++) {
s[i] = '0';
add_element(s);
s[i] = '1';
}
generate_strings(n, l, mid);
generate_strings(n, mid + 1, r);
}
void query(int n, int l, int r, vector<int> v, vector <int>& p) {
if(l == r){
p[l] = v[0];
return;
}
vector <int> left;
vector <int> right;
string s;
for(int i = 0; i < n; i++)
s += "0";
for(int i : v)
s[i] = '1';
int mid = (l + r) / 2;
for(int i : v) {
s[i] = '0';
bool val = check_element(s);
if(val == true)
left.push_back(i);
else
right.push_back(i);
s[i] = '1';
}
query(n, l, mid, left, p);
query(n, mid + 1, r, right, p);
}
vector<int> restore_permutation(int n, int w, int r) {
vector <int> v;
vector <int> p(n);
vector <int> pos(n);
generate_strings(n, 0, n - 1);
compile_set();
for(int i = 0; i < n; i++)
v.push_back(i);
query(n, 0, n - 1, v, p);
for(int i = 0; i < n; i++)
pos[p[i]] = i;
return pos;
}
# | 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... |