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;
#define FOR(i, n) for (int i = 0; i < n; i++)
#define PB push_back
#define ALL(x) x.begin(), x.end()
int n;
vector<int> p;
void write(int l, int r){
if (l == r) return;
string s;
FOR(i, n) s += '1';
for (int i = l; i <= r; i++) s[i] = '0';
int mid = (l + r) / 2;
for (int i = l; i <= mid; i++){
s[i] = '1';
add_element(s);
s[i] = '0';
}
write(l, mid); write(mid + 1, r);
}
void solve(int l, int r, vector<int> idx){
if (l == r){
p[idx[0]] = l; return;
}
string s;
FOR(i, n) s += '1';
for (auto x : idx) s[x] = '0';
set<int> in_left;
vector<int> idx_left, idx_right;
for (auto x : idx){
s[x] = '1';
if (check_element(s)) in_left.insert(x);
s[x] = '0';
}
for (auto x : idx){
if (in_left.count(x)) idx_left.PB(x);
else idx_right.PB(x);
}
int mid = (l + r) / 2;
solve(l, mid, idx_left); solve(mid + 1, r, idx_right);
}
vector<int> restore_permutation(int N, int W, int R){
n = N; p.resize(n, 0);
write(0, n - 1);
compile_set();
vector<int> idx(n); iota(ALL(idx), 0);
solve(0, n - 1, idx);
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... |