# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
398349 | kevinxiehk | Unscrambling a Messy Bug (IOI16_messy) | C++17 | 0 ms | 0 KiB |
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"
using namespace std;
// TODO: global variables can be declared here
int ans[128];
int idk[128];
char s[128];
int N;
void add(int l,int x){
if(x==1)return;
for(int i=0;i<N;i++)s[i]='1';
for(int i=l;i<l+x;i++)s[i]='0';
for(int i=l;i<l+x/2;i++){
s[i]='1';
add_element(s);
//cout<<s<<'\n';
s[i]='0';
}
add(l,x/2);
add(l+x/2,x/2);
}
void check(int l,int x,int a){
//cout<<l<<' '<<x<<' '<<a<<'\n';
//for(int i=0;i<N;i++)cout<<idk[i]<<' ';cout<<'\n';
if(x==1){
//cout<<l<<' '<<a<<'\n';
for(int i=0;i<N;i++)if(idk[i]==a)ans[l]=i;
return;
}
for(int i=0;i<N;i++)s[i]='1';
for(int i=0;i<N;i++)if(idk[i]==a)s[i]='0';
for(int i=0;i<N;i++){
if(idk[i]!=a)continue;
s[i]='1';
if(check_element(s))idk[i]=a*2;
else idk[i]=a*2+1;
s[i]='0';
}
check(l,x/2,a*2);
check(l+x/2,x/2,a*2+1);
}
void restore_permutation(int n, int w, int r, int result[]) {
// TODO: implementation
// example solution that checks if p_1 = 2
// Subtask 1 case 6 and 9 accepted
N=n;
add(0,n);
compile_set();
//for(auto x:ele)cout<<x<<'\n';
for(int i=0;i<n;i++)idk[i]=1;
check(0,n,1);
for(int i=0;i<n;i++)result[i]=ans[i];
}