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;
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.cpp: In function 'void retrieve_permutation(int, int, std::string, std::vector<int>&)':
messy.cpp:31:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < mask.size(); i++)
| ~~^~~~~~~~~~~~~
messy.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 0; i < mask.size(); i++)
| ~~^~~~~~~~~~~~~
# | 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... |