#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
string popat(int n, vector<int> p) {
string s(n, '0');
for (int i : p) s[i] = '1';
return s;
}
vector<int> restore_permutation(int n, int w, int r) {
int MAX_BIT = 31-__builtin_clz(n);
vector<int> popbit[MAX_BIT];
for (int bit = 0; bit < MAX_BIT; bit++) {
for (int i = 0; i < n; i++)
if (i&(1<<bit))
popbit[bit].push_back(i);
}
vector<int> last;
for (int bit = 0; bit < MAX_BIT; bit++) {
for (int i : popbit[bit]) {
vector<int> to_add = last;
if (find(to_add.begin(), to_add.end(), i) == to_add.end()) to_add.push_back(i);
else to_add.erase(find(to_add.begin(), to_add.end(), i));
add_element(popat(n, to_add));
}
last = popbit[bit];
}
compile_set();
last = vector<int>();
vector<int> p(n);
for (int bit = 0; bit < MAX_BIT; bit++) {
vector<int> popped;
for (int i = 0; i < n; i++) {
vector<int> to_add = last;
if (find(to_add.begin(), to_add.end(), i) == to_add.end()) to_add.push_back(i);
else to_add.erase(find(to_add.begin(), to_add.end(), i));
if (check_element(popat(n, to_add))) {
p[i] |= (1<<bit);
popped.push_back(i);
}
}
last = popped;
}
return p;
}
Compilation message (stderr)
messy.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
messy_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |