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"
#define pb push_back
using namespace std;
int n;
vector<int>ans;
void build(int l, int r)
{
if(r-l==0) return;
string s;
for(int i=0; i<n; i++) s+='0';
for(int i=l; i<=r; i++) s[i]='1';
int mid=(l+r)>>1;
for(int i=l; i<=mid; i++)
{
s[i]='0';
add_element(s);
// cout<<"add_element "<<s<<endl;
s[i]='1';
}
build(l, mid);
build(mid+1, r);
}
void calc(vector<int>can, int cur)
{
if(can.size()==1)
{
ans[can[0]]=cur;
return;
}
vector<int>v1, v2;
string s;
for(int i=0; i<n; i++) s+='0';
for(int u : can) s[u]='1';
for(int u : can)
{
s[u]='0';
if(check_element(s)) v1.pb(u);
else v2.pb(u);
s[u]='1';
}
calc(v1, cur);
calc(v2, cur+v1.size());
}
vector<int> restore_permutation(int N, int w, int r)
{
n=N; ans.resize(n);
build(0, n-1);
compile_set();
vector<int>can;
for(int i=0; i<n; i++)
can.pb(i);
calc(can, 0);
return ans;
}
# | 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... |