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;
void preDnc(int n, int l, int r) {
string x; for(int i=0;i<n;i++) x+=char((i<l||i>=r)|48);
int m = l+r>>1;
for(int i=l;i<m;i++) {
x[i]='1';
add_element(x);
x[i]='0';
}
if(r-l>2) {
preDnc(n,l,m);
preDnc(n,m,r);
}
}
void postDnc(int n, int l, int r, vector<int> &perm) {
vector<int> v(begin(perm)+l,begin(perm)+r);
string x; for(int i=0;i<n;i++) x+='1'; for(auto i:v) x[i]='0';
int m = l+r>>1;
int cur = l, cur2 = m;
for(auto i: v) {
x[i] = '1';
if(check_element(x)) perm[cur++]=i;
else perm[cur2++]=i;
x[i] = '0';
}
if(r-l>2) {
postDnc(n,l,m,perm);
postDnc(n,m,r,perm);
}
}
std::vector<int> restore_permutation(int n, int w, int r) {
preDnc(n,0,n);
compile_set();
vector<int> perm(n);
iota(perm.begin(),perm.end(),0);
postDnc(n,0,n,perm);
return perm;
}
Compilation message (stderr)
messy.cpp: In function 'void preDnc(int, int, int)':
messy.cpp:6:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
6 | int m = l+r>>1;
| ~^~
messy.cpp: In function 'void postDnc(int, int, int, std::vector<int>&)':
messy.cpp:20:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | int m = l+r>>1;
| ~^~
# | 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... |