# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
370165 | leinad2 | 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 "messy.h"
#include<bits/stdc++.h>
using namespace std;
vector<int>ans;
void add(int l, int r)
{
if(l==r)return;
int m=l+r>>1;
for(int j=l;j<=m;j++)
{
string s;
for(int i=0;i++<n;)
{
if(l<=i&&i<=r)
{
if(i==j)s+='1';
else s+='0';
}
else s+='1';
}
add_element(s);
}
add(l, m);
add(m+1, r);
}
void chk(int l, int r, vector<int>v)
{
if(l==r)
{
ans[v[0]-1]=l-1;
return;
}
int m=l+r>>1;
vector<int>L, R;
int A[130]={};
for(int i=0;i<v.size();i++)
{
A[v[i]]=1;
}
for(int i=0;i<v.size();i++)
{
string s;
for(int j=0;j++<n;)
{
if(A[j])
{
if(j==v[i])s+='1';
else s+='0';
}
else s+='1';
}
if(check_element(s))L.push_back(v[i]);
else R.push_back(v[i]);
}
chk(l, m, L);
chk(m+1, r, R);
}
vector<int>restore_permutation(int n, int w, int r)
{
ans.resize(n);
vector<int>v;for(int i=0;i++<n;)v.push_back(i);
add(1, n);
compile_set();
chk(1, n, v);
return ans;
}