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;
string to_string(vector<bool> const& mask) {
string res;
for (bool b : mask)
res.push_back(b ? '1' : '0');
return res;
}
void insert(int l, int r, vector<bool>& mask) {
if (r - l == 1)
return;
int mid = (l + r) >> 1;
for (int i = l; i < mid; i++) {
mask[i] = true;
add_element(to_string(mask));
mask[i] = false;
}
for (int i = mid; i < r; i++)
mask[i] = true;
insert(l, mid, mask);
for (int i = l; i < r; i++)
mask[i] = i < mid;
insert(mid, r, mask);
for (int i = l; i < mid; i++)
mask[i] = false;
}
void solve(int l, int r, vector<bool>& mask, vector<int>& perm) {
if (r - l == 1) {
int ind;
for (int i = 0; i < mask.size(); i++)
if (!mask[i])
ind = i;
perm[ind] = l;
return;
}
vector<int> lft, rgt;
for (int i = 0; i < mask.size(); i++) {
if (!mask[i]) {
mask[i] = true;
(check_element(to_string(mask)) ? lft : rgt).push_back(i);
mask[i] = false;
}
}
int mid = (l + r) >> 1;
for (int i : rgt)
mask[i] = true;
solve(l, mid, mask, perm);
for (int i : lft)
mask[i] = true;
for (int i : rgt)
mask[i] = false;
solve(mid, r, mask, perm);
for (int i : lft)
mask[i] = false;
}
vector<int> restore_permutation(int n, int w, int r) {
vector<bool> mask(n, false);
insert(0, n, mask);
compile_set();
vector<int> perm(n);
solve(0, n, mask, perm);
return perm;
}
Compilation message (stderr)
messy.cpp: In function 'void solve(int, int, std::vector<bool>&, std::vector<int>&)':
messy.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 0; i < mask.size(); i++)
| ~~^~~~~~~~~~~~~
messy.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < mask.size(); i++) {
| ~~^~~~~~~~~~~~~
messy.cpp:37:17: warning: 'ind' may be used uninitialized in this function [-Wmaybe-uninitialized]
37 | perm[ind] = 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... |