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>
using namespace std;
#define pb push_back
#include "messy.h"
vector <int> digits[256];
vector <int> ans;
int N;
void write(int l=0, int r=N-1, int node=1)
{
if(l==r)
{
return;
}
string str="";
for(int i=0;i<N;i++)
{
if(l<=i && i<=r)
{
str+='0';
}
else
{
str+='1';
}
}
int m=(l+r)/2;
for(int i=l;i<=m;i++)
{
str[i]='1';
add_element(str);
str[i]='0';
}
write(l,m,node*2);
write(m+1,r,node*2+1);
}
void read(int l=0, int r=N-1, int node=1)
{
if(l==r)
{
ans[digits[node][0]]=l;
return;
}
string str="";
for(int i=0;i<N;i++)
{
str+='1';
}
for(int i=0;i<digits[node].size();i++)
{
str[digits[node][i]]='0';
}
for(int i=0;i<digits[node].size();i++)
{
str[digits[node][i]]='1';
if(check_element(str))
{
digits[node*2].pb(digits[node][i]);
}
else
{
digits[node*2+1].pb(digits[node][i]);
}
str[digits[node][i]]='0';
}
int m=(l+r)/2;
read(l,m,node*2);
read(m+1,r,node*2+1);
}
std::vector<int> restore_permutation(int n, int w, int r)
{
N=n;
write();
compile_set();
ans=vector <int> (N);
for(int i=0;i<N;i++)
{
digits[1].pb(i);
}
read();
return ans;
}
Compilation message (stderr)
messy.cpp: In function 'void read(int, int, int)':
messy.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i=0;i<digits[node].size();i++)
| ~^~~~~~~~~~~~~~~~~~~~
messy.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i=0;i<digits[node].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... |