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;
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
//#define int long long
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
vector<int> ans;
string str;
void build(int l, int r) {
if(l == r) {
str[l] = '1';
add_element(str);
str[l] = '0';
return;
}
int m = (l + r) >> 1;
for(int i = l; i <= m; i++) {
str[i] = '1';
add_element(str);
str[i] = '0';
}
for(int i = l; i <= m; i++) {
str[i] = '1';
}
build(m + 1, r);
for(int i = l; i <= m; i++) {
str[i] = '0';
}
build(l, m);
}
void find(int l, int r, vector<int> a) {
if(l == r) {
ans[l] = a[0];
return;
}
int m = (l + r) >> 1;
vector<int> L, R;
for(int i = l; i <= r; i++) {
int x = a[i - l];
str[x] = '1';
if(check_element(str)) L.pb(x);
else R.pb(x);
}
for(int x : L) {
str[x] = '1';
}
find(m + 1, r, R);
for(int x : L) {
str[x] = '0';
}
find(l, m, L);
}
vector<int> restore_permutation(int n, int w, int r) {
vector<int> a(n); iota(all(a), 0);
ans.resize(n);
str = string(n, '0');
build(0, n - 1);
compile_set();
str = string(n, '0');
find(0, n - 1, a);
return ans;
}
# | 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... |