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 "messy.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
vector<int>ans;
int N;
void insertion(int l,int r){
if(l==r)return;
int mid=(l+r)>>1;
string s=string(N,'0');
for(int i=l;i<=r;i++)s[i]='1';
for(int i=l;i<=mid;i++){
s[i]='0';
add_element(s);
s[i]='1';
}
insertion(l,mid),insertion(mid+1,r);
}
bool dontcare[128];
void finding(int l,int r){
if(l==r){
for(int i=0;i<N;i++){
if(!dontcare[i]){
ans[i]=l;
break;
}
}
return;
}
int mid=(l+r)>>1;
vector<int>firsthalf,secondhalf;
int mxsz=mid-l+1;
string s=string(N,'0');
for(int i=0;i<N;i++){
if(!dontcare[i]){
s[i]='1';
}
}
for(int i=0;i<N;i++){
if(!dontcare[i]){
if(firsthalf.size()==mxsz){
secondhalf.pb(i);
}
else if(secondhalf.size()==mxsz){
firsthalf.pb(i);
}else{
s[i]='0';
bool res=check_element(s);
if(res){
firsthalf.pb(i);
}else{
secondhalf.pb(i);
}
s[i]='1';
}
}
}
for(int i:secondhalf){
dontcare[i]=1;
}
finding(l,mid);
for(int i:firsthalf){
dontcare[i]=1;
}
for(int i:secondhalf){
dontcare[i]=0;
}
finding(mid+1,r);
for(int i:firsthalf){
dontcare[i]=0;
}
}
std::vector<int> restore_permutation(int n, int w, int r) {
N=n;
insertion(0,n-1);
compile_set();
ans=vector<int>(n);
memset(dontcare,0,sizeof(dontcare));
finding(0,n-1);
return ans;
}
Compilation message (stderr)
messy.cpp: In function 'void finding(int, int)':
messy.cpp:48:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
48 | if(firsthalf.size()==mxsz){
| ~~~~~~~~~~~~~~~~^~~~~~
messy.cpp:51:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
51 | else if(secondhalf.size()==mxsz){
| ~~~~~~~~~~~~~~~~~^~~~~~
# | 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... |