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;
const int N = 128;
vector<int> p;
void build(int l, int r, int n) {
if(l == r) return;
int mid = l + r >> 1;
string s(n, '0');
for(int i = 0; i < l; ++i) s[i] = '1';
for(int i = r + 1; i < n; ++i) s[i] = '1';
for(int i = l; i <= mid; ++i) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
build(l, mid, n);
build(mid + 1, r, n);
}
void rec(int l, int r, vector<int> responsible, int n) {
if(l == r) {
p[responsible[0]] = l;
return;
}
int mid = l + r >> 1;
string s(n, '1');
for(auto x: responsible) s[x] = '0';
vector<int> v1, v2;
for(int i = 0; i < n; ++i) {
if(s[i] == '0') {
s[i] = '1';
if(check_element(s)) {
v1.push_back(i);
} else v2.push_back(i);
s[i] = '0';
}
}
rec(l, mid, v1, n);
rec(mid + 1, r, v2, n);
}
std::vector<int> restore_permutation(int n, int w, int r) {
build(0, n - 1, n);
compile_set();
p.assign(n, -1);
vector<int> paiu(n);
iota(paiu.begin(),paiu.end(), 0);
rec(0, n - 1, paiu, n);
return p;
}
Compilation message (stderr)
messy.cpp: In function 'void build(int, int, int)':
messy.cpp:10:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
10 | int mid = l + r >> 1;
| ~~^~~
messy.cpp: In function 'void rec(int, int, std::vector<int>, int)':
messy.cpp:29:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
29 | int mid = 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... |