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 "messy.h"
#include <bits/stdc++.h>
using namespace std; using ii = pair<int,int>; using ll = long long; using vi = vector<int>;
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define per(i,a,b) for (auto i = (b); i >= (a); --i)
#define all(x) begin(x), end(x)
#define siz(x) int((x).size())
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)
#define fi first
#define se second
#define dbg(...) fprintf(stderr,__VA_ARGS__)
inline void flip(char &c) {
if (c == '1') c = '0';
else c = '1';
}
void step1(string s, int l, int r) {
if (l+1 == r) return;
int m = (l+r)/2;
rep(i,l,m-1) s[i] = '1', add_element(s), s[i] = '0';
rep(i,l,m-1) s[i] = '1';
step1(s,m,r);
rep(i,l,m-1) s[i] = '0';
rep(i,m,r-1) s[i] = '1';
step1(s,l,m);
}
vi p;
void step2(string s, int l, int r, vi idxs) {
assert( r-l == siz(idxs) );
if (l+1 == r) {
p[idxs[0]] = l;
return;
}
int m = (l+r)/2;
vi front, back;
for (auto i : idxs) {
s[i] = '1';
if (check_element(s)) front.push_back(i);
else back.push_back(i);
s[i] = '0';
}
for (auto i : front) s[i] = '1';
step2(s,m,r,back);
for (auto i : front) s[i] = '0';
for (auto i : back) s[i] = '1';
step2(s,l,m,front);
}
vi restore_permutation(int n, int w, int r) {
step1(string(n,'0'),0,n);
compile_set();
vi idxs(n); iota(all(idxs),0);
p.resize(n);
step2(string(n,'0'),0,n,idxs);
return p;
}
# | 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... |