# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
886607 | velislavgarkov | 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 <iostream>
#include <vector>
#include "messy.h"
using namespace std;
string sbeg, s1, cur;
vector <int> curv, lef, ri;
vector <int> ans;
int n;
void add_el(int l, int r) {
if (l>=r) return;
int mid=(l+r)/2;
s1=sbeg;
for (int i=l;i<=r;i++) s1[i]='0';
for (int i=l;i<=mid;i++) {
cur=s1;
cur[i]='1';
add_element(cur);
}
add_el(l,mid);
add_el(mid+1,r);
}
void check_el(int l, int r, vector <int> v) {
if (l==r) ans[l]=v[0];
if (l>=r) return;
if (!lef.empty()) lef.clear();
if (!ri.empty()) ri.clear();
s1=sbeg;
for (auto i:v) s1[i]='0';
for (auto i:v) {
cur=s1;
cur[i]='1';
if (check_element(cur)) {
lef.push_back(i);
} else {
ri.push_back(i);
}
}
int mid=(l+r)/2;
check_el(l,mid,lef);
check_el(mid+1,r,ri);
}
vector <int> restore_permutaion(int N, int w, int r) {
ans.resize(N);
n=N;
for (int i=0;i<n;i++) {
sbeg+='1';
cur+='1';
}
add_el(0,n-1);
compile_set();
for (int i=0;i<n;i++) curv.push_back(i);
check_el(0,n-1,curv);
return ans;
}