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;
void do_add(string s, int l, int r){
if(l == r) return;
int m = (l+r)/2;
for(int i = l; i <= r; i++) s[i] = '0';
for(int i = l; i <= m; i++){
s[i] = '1';
// cerr << s << "\n";
add_element(s);
s[i] = '0';
}
for(int i = l; i <= m; i++) s[i] = '1';
do_add(s, m+1, r);
for(int i = l; i <= m; i++) s[i] = '0';
for(int i = m+1; i <= r; i++) s[i] = '1';
do_add(s, l, m);
}
vector<int> p;
void solve(string s, vector<int> v, int res, int val){
if(val == 0){
p[v[0]] = res;
return;
}
for(int i : v) s[i] = '0';
vector<int> a, b;
for(int i : v){
s[i] = '1';
if(check_element(s)) a.push_back(i);
else b.push_back(i);
s[i] = '0';
}
for(int i : a) s[i] = '1';
solve(s, b, res+val, val/2);
for(int i : a) s[i] = '0';
for(int i : b) s[i] = '1';
solve(s, a, res, val/2);
}
vector<int> restore_permutation(int n, int w, int r){
w--, r--; // suppress warning
string s(n, '0');
do_add(s, 0, n-1);
compile_set();
vector<int> v(n);
for(int i = 0; i < n; i++) v[i] = i;
p.resize(n);
solve(s, v, 0, n/2);
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... |