# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40988 | MatheusLealV | 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;
int n;
int* restore_permutation(int N_, int w, int r)
{
n = N_;
int *ans = new int[n];
for(int i = 0; i < n; i++) ans[i] = -1;
for(int i = 0; i < n; i++)
{
string s = "";
int qtd = i + 1;
for(int p = 0; p < n; p++)
{
if(qtd > 0) s.push_back('1');
else s.push_back('0');
qtd --;
}
reverse(s.begin(), s.end());
add_element(s);
//cout<<"ADD "<<s<<"\n";
}
compile_set();
//memset(ans, -1, sizeof ans);
string ant = "";
for(int i = 0; i < n; i++) ant.push_back('0');
for(int bit = 1, pos = n - 1; bit <= n; bit ++, pos --)
{
vector<string> all;
for(int i = 0; i < n; i++)
{
if(ant[i] == '0')
{
string aux = ant;
aux[i] = '1';
all.push_back(aux);
}
}
//random_shuffle(all.begin(), all.end());
bool jafoi = false;
for(auto s: all)
{
if(jafoi) break;
if(check_element(s))
{
//cout<<s<<"\n";
for(int i = 0; i < s.size(); i++)
{
if(s[i] == '1' && ans[i] == -1)
{
ans[i] = pos;
jafoi = true;
break;
}
}
ant = s;
}
}
}
return ans;
}