#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
void insert_all(int n, int j, string mask)
{
if (n == 1)
return;
string mask1(mask.begin(), mask.end()), mask2(mask.begin(), mask.end());
for (int i = j; i < j + n / 2; i++)
{
string s(mask.begin(), mask.end());
s[i] = '1';
add_element(s);
mask2[i] = '1';
}
for (int i = j + n / 2; i < j + n; i++)
mask1[i] = '1';
insert_all(n / 2, j, mask1);
insert_all(n / 2, j + n / 2, mask2);
}
void retrieve_permutation(int n, int j, string mask, vector<int> &p)
{
if (n == 1)
{
for (int i = 0; i < mask.size(); i++)
if (mask[i] == '0')
{
p[i] = j;
return;
}
}
string mask1(mask.begin(), mask.end()), mask2(mask.begin(), mask.end());
for (int i = 0; i < mask.size(); i++)
{
if (mask[i] == '0')
{
string s(mask.begin(), mask.end());
s[i] = '1';
if (check_element(s))
mask2[i] = '1';
else
mask1[i] = '1';
}
}
retrieve_permutation(n / 2, j, mask1, p);
retrieve_permutation(n / 2, j + n / 2, mask2, p);
}
std::vector<int> restore_permutation(int n, int w, int r)
{
string mask;
for (int i = 0; i < n; i++)
mask.push_back('0');
insert_all(n, 0, mask);
compile_set();
vector<int> p(n);
retrieve_permutation(n, 0, mask, p);
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... |