# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
40988 | MatheusLealV | Unscrambling a Messy Bug (IOI16_messy) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}