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 "messy.h"
//#include "grader.cpp"
#include <set>
#include <vector>
#include <iostream>
using namespace std;
vector <int> ansPerm;
void gen(int l, int r, int n)
{
if(l==r) return;
string curr = "";
for(int i = 0;i<n;i++)
{
if(i>=l && i<=r) curr += "0";
else curr += "1";
}
for(int i = l;i<=(l+r)/2;i++)
{
curr[i] = '1';
add_element(curr);
curr[i] = '0';
}
gen(l, (l+r)/2, n);
gen((l+r)/2+1, r, n);
}
void solve(int l, int r, set <int> s, int n)
{
if(l==r)
{
ansPerm[*s.begin()] = l;
return;
}
set <int> lhs, rhs;
for(int x: s)
{
string curr = "";
for(int i = 0;i<n;i++)
{
if(s.count(i)==false) curr += "1";
else
{
if(i==x) curr += "1";
else curr += "0";
}
}
if(check_element(curr)==true) lhs.insert(x);
else rhs.insert(x);
}
solve(l, (l+r)/2, lhs, n);
solve((l+r)/2+1, r, rhs, n);
}
vector<int> restore_permutation(int n, int w, int r)
{
gen(0, n-1, n);
compile_set();
ansPerm.resize(n);
set <int> s;
for(int i = 0;i<n;i++) s.insert(i);
solve(0, n-1, s, n);
return ansPerm;
}
# | 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... |