# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1187740 | Mamikonm1 | Unscrambling a Messy Bug (IOI16_messy) | C++20 | 0 ms | 0 KiB |
#include <iostream>
#include<vector>
#include<cmath>
#include<set>
#include<algorithm>
#include<random>
#include "messy.h"
using namespace std;
mt19937 rd(time(nullptr));
void comp(string& a, vector<int>& f) {
string b = string(n, '0');
for (int i = 0; i < n; ++i)
b[i] = a[f[i]];
a = b;
}
vector<int> restore_permutation(int n, int w, int r) {
vector<int>f(n), ans(n);
vector<string>s(n, string(n, '0'));
for (int i = 0; i < n; ++i) {
f[i] = i;
for (int j = 0; j <= i; ++j)
s[i][j] = '1';
}
shuffle(begin(f), end(f), rd);
for (int i = 0; i < n; ++i) {
comp(s[i], f);
add_element(s[i]);
}
compile_set();
int ind;
string t = string(n, '0'), g;
g = t;
for (int i = 0; i < n; ++i) {
ind = 0;
for (int j = 0; j < n; ++j) {
if (g[j] == '0' and s[i][j] == '1') {
ind = j;
}
}
g[ind] = '1';
for (int j = 0; j < n; ++j) {
if (t[j] == '0') {
t[j] = '1';
if (check_element(t)) {
ans[j] = ind;
break;
}
t[j] = '0';
}
}
}
return ans;
}