# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
747716 | _martynas | Unscrambling a Messy Bug (IOI16_messy) | C++11 | 2 ms | 496 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;
#define PB push_back
using vi = vector<int>;
struct Group {
vi from, to;
};
vi restore_permutation(int n, int w, int r) {
/*
add_element("0");
compile_set();
check_element("0");
*/
int B = __builtin_ctz(n);
for(int b = B; b >= 1; b--) {
for(int i = 0; i < n; i += 1<<b) {
for(int j = i; j < i+(1<<b)/2; j++) {
string s(n, '1');
fill(s.begin()+i, s.begin()+i+(1<<b), '0');
s[j] = '1';
add_element(s);
}
}
}
compile_set();
vector<Group> G;
{
Group g;
for(int i = 0; i < n; i++) g.from.PB(i), g.to.PB(i);
G.PB(g);
}
for(int b = B; b >= 1; b--) {
vector<Group> Gp;
for(auto g : G) {
// from should be consecutive positions
vi set_bits, unset_bits;
for(int i : g.to) {
string s(n, '1');
for(int j : g.to) s[j] = '0';
s[i] = '1';
bool resp = check_element(s);
if(resp) {
set_bits.PB(i);
}
else {
unset_bits.PB(i);
}
}
Group gl, gr;
for(int i = 0; i < g.from.size(); i++) {
if(i < g.from.size()/2) {
gl.from.PB(g.from[i]);
gl.to.PB(set_bits[i]);
}
else {
gr.from.PB(g.from[i]);
gr.to.PB(unset_bits[i - g.from.size()/2]);
}
}
Gp.PB(gl); Gp.PB(gr);
}
G = Gp;
}
vi ans(n);
for(int i = 0; i < n; i++) {
ans[G[i].to[0]] = G[i].from[0];
}
return ans;
}
/*
4 100 100 2 1 3 0
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |