이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]='0';
add_element(tmp);
tmp[i-1]='1';
}
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]='0';
if(check_element(tmp)){
hi=mid;
}else{
lo=mid+1;
}
ext++;
}
p[k]=lo-1;
}
vector<int> restore_permutation(int n, int w, int r) {
logn=log2(n);
N=n;
if(n==8){
//first phase write
string s;
for(int i=0;i<n;i++){
s+='0';
}
for(int i=1;i<=n;i++){
s[i-1]='1';
add_element(s);
}
//compile set
compile_set();
//first phase read
string f;
for(int i=0;i<n;i++){
f+='0';
}
for(int i=1;i<=n;i++){
for(int j=0;j<n;j++){
if(f[j]=='1') continue;
f[j]='1';
if(check_element(f)){
p[j]=i-1;
break;
}
f[j]='0';
}
}
//answer
return vector<int>(p,p+n);
}else{
//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]);
}
for(int i=1;i<=logn+1;i++){//complement
for(int j=0;j<n;j++){
extra_s[i][j]=(extra_s[i][j]=='1')?'0':'1';
}
}
//second phase write
p2write(logn+2,n,1);
//compile set
compile_set();
//first phase read
for(int i=0;i<n;i++){
extra_f[0]+='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';
}
}
for(int i=1;i<=logn+1;i++){//complement
for(int j=0;j<n;j++){
extra_f[i][j]=(extra_f[i][j]=='1')?'0':'1';
}
}
//second phase read
for(int i=0;i<n;i++){
if(extra_f[logn+1][i]=='1') continue;
bsearch(i);
}
//answer
return 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... |