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;
typedef long long ll;
/*
string toBin(int num)
{
string res;
while (num > 0)
{
res += (num %= 2) - '0';
res /= 2;
}
return res;
}*/
int n;
void cons(int a, int b, int pa, int pb, int node)
{
if (node % 2 == 1)
{
string cur (n, '1');
for (int i = pa; i<= pb; i++) cur[i] = '0';
for (int i = a; i <= b; i++)
{
cur[i] = '1';
add_element(cur);
//cout << cur << " " << "a" << " " << a << " " << b << " " << pa << " " << pb <<endl;
cur[i] = '0';
}
}
if (a == b) return;
int mid =(a + b) / 2;
cons(a, mid, a, b, node * 2);
cons(mid + 1, b, a, b, node * 2 + 1);
}
vector<int> solve(vector<int> on)
{
if (!on.empty())
{
/*
for (int i : on) cout << i << " ";
cout << endl; */
}
if (on.size() == 1) return on;
string cur (n, '1');
for (int i : on) cur[i] = '0';
vector<int> leftt;
vector<int> rightt;
for (int i : on)
{
cur[i] = '1';
//cout << on.size() << " "<< i << " " << cur << endl;
if (check_element(cur))
{
//cout << "Oj" << endl;
rightt.push_back(i);
}
else leftt.push_back(i);
cur[i] = '0';
}
leftt = solve(leftt);
rightt = solve(rightt);
vector<int> res;
for (int i : leftt) res.push_back(i);
for (int i : rightt) res.push_back(i);
return res;
}
std::vector<int> restore_permutation(int N, int w, int r) {
n = N;
cons(0, n - 1, 0, n - 1, 0);
compile_set();
vector<int> on;
for (int i = 0; i < n; i++) on.push_back(i);
on = solve(on);
vector<int> res(n);
for (int i = 0; i < n; i++) res[on[i]] = i;
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... |