# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
771368 | tigar | 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;
map<int, int>permutation;
vector<string> adding(int n)
{
vector<string>ans;
if(n==0)return ans;
string s, s1;
for(int i=0; i<n; i++)s+='0';
for(int i=0; i<n/2; i++){s[i]='1'; ans.push_back(s); s[i]='0'; s1+='1';}
vector<string>p=adding(n/2);
for(int i=0; i<p.size(); i++){ans.push_back(p[i]+s1); ans.push_back(s1+p[i]);}
return ans;
}
void reading(int l, int r, vector<int>possible)
{
vector<int>ans1, ans2;
if(l==r+1)
{
string s;
for(int i=0; i<n; i++)
{
if(i==possible[1])s+='0'
else s+='1';
}
if(check_element(s)){permutation[l]=possible[0]; permutation[r]=possible[1];}
else {permutation[l]=possible[0]; permission[r]=possible[1];}
return;
}
string s;
for(int i=0; i<n; i++)s+='1';
for(int i=0; i<possible.size(); i++)s[possible[i]]='0';
for(int i=0; i<possible.size(); i++)
{
s[possible[i]]='1';
if(check_element(s))ans1.push_back(possible[i]);
else ans2.push_back(possible[i]);
s[possible[i]]='0';
}
reading(l, (l+r)/2-1, ans1);
reading((r+l)/2, r, ans2);
return;
}
std::vector<int>
//void
restore_permutation(int n, int w, int r)
{
vector<string>a=adding(n);
for(int i=0; i<a.size(); i++)add_element(a[i]);
compile_set();
vector<int>b;
for(int i=0; i<n; i++)b.push_back(i);
reading(0, n-1, b);
vector<int>ans;
for(int i=0; i<n; i++)ans.push_back(permutation[i]);
return ans;
}