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;
typedef long long ll;
vector<int> res;
void find(int l, int r, vector<int> idx, int n)
{
/* // debug
cout << "(l, r) = (" << l << ", " << r << ")\n";
cout << "idx = [";
for (int x : idx)
cout << x << " ";
cout << "]\n";
*/
if (l == r)
{
res[idx[0]] = l;
return;
}
// assuming we know the indices in idx are mapped to the range [l, r]
vector<int> left_idx, right_idx;
for (int i : idx)
{
string s(n, '1');
for (int j : idx)
if (j != i)
s[j] = '0';
if (check_element(s))
left_idx.push_back(i);
else
right_idx.push_back(i);
}
int m = (l + r) / 2;
find(l, m, left_idx, n);
find(m + 1, r, right_idx, n);
}
vector<int> restore_permutation(int n, int w, int r)
{
// consider a number of the form
//
// 10000000
// 01000000
// 00100000
// 00010000
//
// or something like that, so we can halve the searching space.
for (int k = 1; k < n; k *= 2)
{
// cout << k << '\n';
for (int i = 0; i < n; i += 2 * k)
{
string s(n, '1');
for (int j = i; j < i + 2 * k; j++)
s[j] = '0';
for (int j = i; j < i + k; j++)
{
s[j] = '1';
// cout << s << '\n';
add_element(s);
s[j] = '0';
}
}
}
compile_set();
vector<int> idx(n);
for (int i = 0; i < n; i++)
idx[i] = i;
res.resize(n);
find(0, n - 1, idx, n);
return res;
}
# | 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... |