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 <vector>
#include <iostream>
#include <assert.h>
#include "messy.h"
using namespace std;
int P[200];
int N;
void inserimento(string s){
//cout<<"ins "<<s<<endl;
add_element(s);
}
bool controllo(string s){
bool f=check_element(s);
//cout<<"con "<<s<<" "<<f<<endl;
return f;
}
void crea(int a, int b){
if(a==b)
return;
string s(N,'0');
for(int i=0;i<a;i++)
s[i]='1';
for(int i=b+1;i<N;i++)
s[i]='1';
s[a]='1';
inserimento(s);
for(int i=a+1;i<=(a+b)/2;i++){
s[i]='1';
inserimento(s);
s[i]='0';
}
crea(a,(a+b)/2);
crea((a+b)/2+1,b);
}
void cerca(string S, int a, int b){
int pos=-1;
vector<int> X,Y;
for(int i=0;i<N;i++)
if(S[i]=='0'){
S[i]='1';
if(controllo(S)){
pos=i;
X.push_back(i);
break;
}
S[i]='0';
}
assert(pos!=-1);
for(int i=0;i<N;i++)
if(S[i]=='0'){
S[i]='1';
if(controllo(S))
X.push_back(i);
else
Y.push_back(i);
S[i]='0';
}
assert(X.size()==Y.size());
if(X.size()==1){
P[X[0]]=a;
P[Y[0]]=b;
}
else{
string A(N,'1'),B(N,'1');
for(int i:X)
A[i]='0';
cerca(A,a,(a+b)/2);
for(int i:Y)
B[i]='0';
cerca(B,(a+b)/2+1,b);
}
}
vector<int> restore_permutation(int n, int w, int r) {
N=n;
crea(0,N-1);
compile_set();
string v(N,'0');
cerca(v,0,N-1);
vector<int> ans(N);
for(int i=0;i<N;i++)
ans[i]=P[i];
return ans;
}
/*
32 320 1024
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
*/
# | 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... |