# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
207909 | DodgeBallMan | Unscrambling a Messy Bug (IOI16_messy) | C++14 | 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;
vector<int> vec;
int n, p[150];
string element( int l, int r, int idx ) {
string s( n, '1' );
for( int i = l ; i <= r ; i++ ) s[i] = '0';
s[idx] = '1';
return s;
}
string question( vector<int> &v, int idx ) {
string s( n, '1' );
for( int i : v ) s[i] = '0';
s[idx] = '1';
return s;
}
void add( int l = 0, int r = n - 1 ) {
if( l == r ) return ;
int mid = l + r >> 1;
for( int i = l ; i <= mid ; i++ ) add_element( element( l, r, i ) );
add( l, mid ), add( mid + 1, r );
}
void solve( vector<int> &v, int l = 0, int r = n - 1 ) {
if( l == r ) return void( p[v[0]] = l );
vector<int> le, ri;
for( int i : v ) {
bool side = check_element( question( v, i ) );
if( side ) le.emplace_back( i );
else ri.emplace_back( i );
}
int mid = l + r >> 1;
solve( le, l, mid ), solve( ri, mid + 1, r );
}
int restore_permutation( int N, int w, int r ) {
n = N;
add(), compile_set();
for( int i = 0 ; i < n ; i++ ) vec.emplace_back( i );
solve( vec );
return p;
}