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;
int n;
vector<int> ans;
void set_element(int l, int r) {
if (l == r) return;
int m = (l + r) / 2;
string x(n, '0');
for (int i = 0; i < n; i++)
if (i < l || i > r) x[i] = '1';
for (int i = l; i <= m; i++) {
string k = x;
k[i] = '1';
add_element(k);
}
set_element(l, m);
set_element(m+1, r);
}
void get(int l, int r, vector<bool> pos) {
if (l == r) {
int val;
for (int i = 0; i < n; i++)
if (pos[i]) val = i;
ans[val] = l;
return;
}
vector<bool> left(n, false), right(n, false);
string x(n, '0');
for (int i = 0; i < n; i++)
if (!pos[i]) x[i] = '1';
for (int i = 0; i < n; i++) {
if (pos[i]) {
string j = x;
j[i] = '1';
if (check_element(j)) left[i] = true;
else right[i] = true;
}
}
int m = (l + r) / 2;
get(l, m, left);
get(m+1, r, right);
}
vector<int> restore_permutation(int N, int w, int r) {
n = N;
ans.resize(n);
vector<bool> pos(n, true);
set_element(0, n-1);
compile_set();
get(0, n-1, pos);
return ans;
}
Compilation message (stderr)
messy.cpp: In function 'void get(int, int, std::vector<bool>)':
messy.cpp:33:12: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
33 | ans[val] = l;
| ^
# | 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... |