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>
using namespace std;
#include "messy.h"
#include<bits/stdc++.h>
int ans[130];
vector<string> subsets;
void createSubsets(int l, int r, int n)
{
if(l != r)
{
int mid = (l + r) /2;
string s(n, '1');
for(int i = l; i <=r; i ++)
{
s[i] = '0';
}
for(int i = l; i <=mid; i ++)
{
string a = s;
a[i] = '1';
subsets.push_back(a);
add_element(a);
}
createSubsets(l, mid, n);
createSubsets(mid + 1, r, n);
}
}
void query(int l, int r, int n, vector<int> ones)
{
/*
cout << l << " and " << r <<"\nones: ";
for(auto val: ones)
{
cout << val << " ";
}cout << '\n';
*/
if(l == r)
{
for(int i= 0; i <n; i ++)
{
bool inones = false;
for(int j = 0; j <ones.size(); j ++)
{
if(ones[j] == i)
{
inones = true;
}
}
if(!inones)
{
//cout << l << "corresponds to " << i << '\n';
ans[i] = l;
return;
}
}
}
int mid = (l + r) / 2;
vector<int> futurelefts, futurerights;
string s(n, '0');
for(auto idx: ones)
{
s[idx] = '1';
}
for(int i = 0; i <n; i ++)
{
if(s[i] == '0')
{
string a = s;
a[i] = '1';
if(check_element(a))
{ //cout << a << " checnekd \n";
futurerights.push_back(i);
}
else
{
futurelefts.push_back(i);
//cout << a << " notchecked \n";
}
}
}
for(auto val:ones)
{
futurelefts.push_back(val);
futurerights.push_back(val);
}
query(l, mid, n, futurelefts);
query(mid + 1, r, n, futurerights);
}
vector<int> restore_permutation(int n, int w, int r) {
createSubsets(0, n-1, n );
compile_set();
/*
for(string s : subsets)
{
cout << s << '\n';
}
cout << '\n';*/
vector<int> a;
query(0, n-1, n, a);
vector<int> ret;
for(int i = 0; i <n; i ++)
{
ret.push_back(ans[i]);
}
return ret;
}
Compilation message (stderr)
messy.cpp: In function 'void query(int, int, int, std::vector<int>)':
messy.cpp:45:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int j = 0; j <ones.size(); j ++)
| ~~^~~~~~~~~~~~
# | 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... |