# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1268742 | BlockOG | Unscrambling a Messy Bug (IOI16_messy) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
// mrrrow meeow :3
// go play vivid/stasis now! it's free on steam
#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;
int ____init = [] {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
return 0;
}();
void add_element(string x);
void compile_set();
bool check_element(string x);
void fill(int l, int r, int n) {
if (r - l <= 1) return;
int m = (l + r) / 2;
string thing, thing2;
fo(_, 0, l) thing += '1';
fo(_, l + 1, n) thing2 += '0' + (_ >= r);
fo(i, l, m) {
add_element(thing + '1' + thing2);
thing += '0';
thing2 = thing2.substr(1);
}
fill(l, m, n);
fill(m, r, n);
}
void get(set<int> curr, int l, int r, int n, int *result) {
if (r - l <= 1) {
result[*curr.begin()] = l;
return;
}
int m = (l + r) / 2;
set<int> left, right;
for (int i : curr) {
string thing;
fo(j, 0, n) thing += '0' + (!curr.count(j) || j == i);
if (check_element(thing)) left.insert(i);
else right.insert(i);
}
get(left, l, m, n, result);
get(right, m, r, n, result);
}
void restore_permutation(int n, int w, int r, int *result) {
fill(0, n, n);
compile_set();
set<int> curr;
fo(i, 0, n) curr.insert(i);
get(curr, 0, n, n, result);
}