#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
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 |
1 |
Correct |
0 ms |
348 KB |
n = 8 |
2 |
Correct |
0 ms |
436 KB |
n = 8 |
3 |
Correct |
1 ms |
348 KB |
n = 8 |
4 |
Correct |
0 ms |
348 KB |
n = 8 |
5 |
Correct |
0 ms |
348 KB |
n = 8 |
6 |
Correct |
0 ms |
348 KB |
n = 8 |
7 |
Correct |
0 ms |
388 KB |
n = 8 |
8 |
Correct |
0 ms |
348 KB |
n = 8 |
9 |
Correct |
0 ms |
348 KB |
n = 8 |
10 |
Correct |
0 ms |
348 KB |
n = 8 |
11 |
Correct |
0 ms |
348 KB |
n = 8 |
12 |
Correct |
1 ms |
348 KB |
n = 8 |
13 |
Correct |
0 ms |
408 KB |
n = 8 |
14 |
Correct |
0 ms |
348 KB |
n = 8 |
15 |
Correct |
1 ms |
348 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
grader returned WA |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
n = 32 |
2 |
Correct |
1 ms |
348 KB |
n = 32 |
3 |
Correct |
1 ms |
432 KB |
n = 32 |
4 |
Incorrect |
0 ms |
348 KB |
grader returned WA |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
grader returned WA |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
grader returned WA |
2 |
Halted |
0 ms |
0 KB |
- |