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<bits/stdc++.h>
using namespace std;
#define pb push_back
#include "messy.h"
string test;
vector<int> ans;
vector<int> v;
int bruh,hsh[128],it=0,answer[128];
void build(int st,int ed)
{
int md=(st+ed)/2;
if(st==ed)
{
return;
}
test.clear();
for(int i=1;i<=bruh;i++)test.pb('1');
for(int i=st;i<=ed;i++)test[i-1]='0';
for(int i=st;i<=md;i++)
{
test[i-1]='1';
//cout << test << endl;
add_element(test);
test[i-1]='0';
}
build(st,md);
build(md+1,ed);
}
void finalize(int st,int ed)
{
vector<int> nathan,pasin;
int md=(st+ed)/2;
if(st==ed)
{
memset(hsh,0,sizeof hsh);
for(int i=0;i<v.size();i++)
{
//printf("%d ",v[i]);
++hsh[v[i]];
}
//printf("\n");
for(int i=0;i<bruh;i++)
{
if(hsh[i]==0)
{
answer[i]=it;
++it;
}
}
return;
}
//printf("%d %d\n",st,ed);
test.clear();
for(int i=1;i<=bruh;i++)test.pb('0');
for(int i=0;i<v.size();i++)test[v[i]]='1';
for(int i=1;i<=bruh;i++)
{
if(test[i-1]=='0')
{
test[i-1]='1';
//cout << test << endl;
if(check_element(test)==1)
{
nathan.pb(i-1);
}else
{
v.push_back(i-1);
pasin.pb(i-1);
}
test[i-1]='0';
}
}
/*printf("v\n");
for(int i=0;i<v.size();i++)
{
printf("%d ",v[i]);
}
printf("\n");
printf("nathan\n");
for(int i=0;i<nathan.size();i++)
{
printf("%d ",nathan[i]);
}
printf("\n");
printf("pasin\n");
for(int i=0;i<pasin.size();i++)
{
printf("%d ",pasin[i]);
}
printf("\n");*/
finalize(st,md);
////
/*
code ever!!
for(int i=0;i<pasin.size();i++)v.pop_back();
for(int i=0;i<nathan.size();i++)
{
v.pb(nathan[i]);
}
*/
////
// printf("pasin\n");
// for(int i=0;i<pasin.size();i++)
// {
// printf("%d ",pasin[i]);
// }
// printf("\n");
memset(hsh,0,sizeof hsh);
v.clear();
for(int i=0;i<pasin.size();i++)
{
++hsh[pasin[i]];
}
for(int i=0;i<bruh;i++)
{
if(hsh[i]==0)v.push_back(i);
}
finalize(md+1,ed);
}
std::vector<int> restore_permutation(int n, int w, int r) {
/*add_element("0");
compile_set();
check_element("0");
return std::vector<int>();*/
bruh=n;
//for(int i=0;i<n;i++)ans.pb(i);
build(1,n);
//printf("\n");
compile_set();
finalize(1,n);
for(int i=0;i<n;i++)ans.pb(answer[i]);
return ans;
}
Compilation message (stderr)
messy.cpp: In function 'void finalize(int, int)':
messy.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
messy.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i=0;i<v.size();i++)test[v[i]]='1';
| ~^~~~~~~~~
messy.cpp:112:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for(int i=0;i<pasin.size();i++)
| ~^~~~~~~~~~~~~
# | 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... |