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 <vector>
#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int n;
void rec0(int l, int r, string s)
{
if (l == r)
return;
int m = (l + r) / 2;
for (int i = l; i <= m; ++i)
{
s[i] = '1';
add_element(s);
s[i] = '0';
}
for (int i = m + 1; i <= r; ++i)
s[i] = '1';
rec0(l, m, s);
for (int i = m + 1; i <= r; ++i)
s[i] = '0';
for (int i = l; i <= m; ++i)
s[i] = '1';
rec0(m + 1, r, s);
}
vector<int> ans;
void rec1(int l, int r, string s)
{
if (l == r)
{
for (int i = 0; i < n; ++i)
{
if (s[i] == '0')
{
ans[i] = l;
}
}
return;
}
int m = (l + r) / 2;
vector<int> v;
for (int i = 0; i < n; ++i)
{
if (s[i] == '0')
{
s[i] = '1';
if (check_element(s))
v.push_back(i);
s[i] = '0';
}
}
string sl = s;
for (int i = 0; i < n; ++i)
{
if (s[i] == '0')
{
if (!binary_search(all(v), i))
sl[i] = '1';
}
}
rec1(l, m, sl);
for (int i = 0; i < sz(v); ++i)
s[v[i]] = '1';
rec1(m + 1, r, s);
}
std::vector<int> restore_permutation(int n, int w, int r)
{
::n = n;
string s;
for (int i = 0; i < n; ++i)
s += '0';
rec0(0, n - 1, s);
compile_set();
ans.assign(n, 0);
rec1(0, n - 1, s);
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... |