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 <bits/stdc++.h>
using namespace std;
#define MAXLOGN 7
#define MAXN 128
string extra_s[9],extra_f[9];
int logn,N,p[MAXN+1];
void p2write(int start,int end,int extra){
if(start==end) return;
//write the first half with 1
int mid=(start+end)/2;
string tmp=extra_s[extra];
for(int i=start;i<=mid;i++){
tmp[i-1]='1';
add_element(tmp);
tmp[i-1]='0';
}
p2write(start,mid,extra+1);
p2write(mid+1,end,extra+1);
}
void bsearch(int k){//k>=logn(k is the position of the search element in p)
int ext=1;
int lo=logn+2,hi=N;
while(lo<hi){
int mid=(lo+hi)/2;
string tmp=extra_f[ext];
tmp[k]='1';
if(check_element(tmp)){
hi=mid;
}else{
lo=mid+1;
}
}
p[k]=lo-1;
}
std::vector<int> restore_permutation(int n, int w, int r) {
logn=log2(n);
N=n;
//first phase write
for(int i=0;i<n;i++){
extra_s[0]+='0';
}
for(int i=1;i<=logn+1;i++){
extra_s[i]=extra_s[i-1];
extra_s[i][i-1]='1';
add_element(extra_s[i]);
}
//second phase write
p2write(logn+2,n,1);
//compile set
compile_set();
//first phase read
extra_f[0]=extra_s[0];
for(int i=1;i<=logn+1;i++){
extra_f[i]=extra_f[i-1];
for(int j=0;j<n;j++){
if(extra_f[i][j]=='1') continue;
extra_f[i][j]='1';
if(check_element(extra_f[i])){
p[j]=i-1;
break;
}
extra_f[i][j]='0';
}
}
//second phase read
for(int i=0;i<n;i++){
if(extra_f[logn+1][i]=='1') continue;
bsearch(i);
}
//answer
return std::vector<int>(p,p+n);
}
# | 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... |