# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
301455 | matheo_apd | 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;
#define maxn 130
int ans[maxn], n_;
void add(int l, int r){
if(l == r) return;
string c;
for(int i = 0; i < n_; i++){
if(l <= i and i <= r) c += '1';
else c += '0';
}
int mid = (l+r)/2;
for(int i = l; i <= mid; i++){
c[i] = '0';
add_element(c);
c[i] = 1;
}
add(l, mid); add(mid+1, r);
}
void solve(int l, int r, vector<int> caras){
if(l == r){
ans[caras[0]] = l;
return;
}
vector<int> L, R;
string c;
for(int i = 0; i < n_; i++){
if(binary_search(caras.begin(), caras.end(), i)) c += '1';
else c += '0';
}
for(int i = 0; i < n_; i++){
if(c[i] == '0') continue;
c[i] = '0';
if(check_element(c)) L.push_back(i);
else R.push_back(i);
c[i] = '1';
}
int mid = (l+r)/2;
solve(l, mid, L);
solve(mid+1, r, R);
}
int[] restore_permutation(int n, int w, int r){
add(0, n-1);
n_ = n;
compile_set();
int resposta[n];
vector<int> caras;
for(int i = 0; i < n; i++)
caras.push_back(i);
solve(0, n-1, c);
for(int i = 0; i < n; i++)
resposta[i] = ans[i];
return resposta;
}