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 <random>
#include <vector>
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
int n;
string get_string(int ones = 0) {
return string(ones, '1') + string(n - ones, '0');
}
void build(int l, int r) {
if (l == r) return;
string s(n, '1');
for (int i = l; i <= r; i++) s[i] = '0';
for (int i = l; i <= (l + r) / 2; i++) {
s[i] = '1';
add_element(s);
// cerr << s << endl;
s[i] = '0';
}
build(l, (l + r) / 2);
build((l + r) / 2 + 1, r);
}
vector<int> get(int l, int r, vector<int> p) {
if (l == r) return p;
string s(n, '1');
for (int i:p) s[i] = '0';
vector<int> left;
vector<int> right;
for (int i:p) {
s[i] = '1';
// cerr << "\t" << s << ' ';
if (check_element(s)) {
// cerr << "true" << endl;
left.push_back(i);
} else {
// cerr << "false" << endl;
right.push_back(i);
}
s[i] = '0';
}
// for (auto x: left) cout << x << ' ';
// cout << " ";
// for (auto y:right) cout << y << ' ';
// cout << endl;
vector<int> res, tmp;
res = get(l, (l + r) / 2, left);
tmp = get((l + r) / 2 + 1, r, right);
for (auto x:tmp) res.push_back(x); // birlashtirish
return res;
}
std::vector<int> restore_permutation(int n, int w, int r) {
::n = n;
vector<int> p(n, -1);
for (int i = 0; i < n; i++) p[i] = i;
build(0, n - 1);
compile_set();
p = get(0, n - 1, p);
vector<int> ans = p;
for (int i = 0; i < n; i++) ans[p[i]] = 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... |