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;
int n=128;
string all_zero="";
vector<int>to(128,0);
void build(int l=0 , int r=n-1, string base=all_zero){
if(l==r) return;
int mid = (l+r)>>1;
for(int i = l; i <= mid; i++){
string tmp = base;
tmp[i]='1';
add_element(tmp);
}
string lft_base=base,rgt_base=base;
for(int i = l; i <= mid; i++){
rgt_base[i]='1';
}
for(int i = mid+1; i <= r; i++){
lft_base[i]='1';
}
build(l,mid,lft_base);
build(mid+1,r,rgt_base);
return;
}
void slv(vector<int>prge,int l=0 , int r=n-1, string base=all_zero){
if(l==r){
to[l]=prge[0];
return;
}
int mid = (l+r)>>1;
vector<int>inlft;
vector<int>inrgt;
for(int i = 0; i < prge.size(); i++){
int ploc = prge[i];
string tmp = base;
tmp[ploc]='1';
bool isq = check_element(tmp);
if(isq==0){
inrgt.push_back(ploc);
}
else{
inlft.push_back(ploc);
}
}
string lft_base=base,rgt_base=base;
for(int loc : inrgt){
lft_base[loc]='1';
}
for(int loc : inlft){
rgt_base[loc]='1';
}
slv(inlft,l,mid,lft_base);
slv(inrgt,mid+1,r,rgt_base);
return;
}
vector<int> restore_permutation(int N, int W, int R) {
n = N;
to.assign(n,0);
for(int i = 0; i < n; i++){
all_zero=all_zero+"0";
}
build();
compile_set();
vector<int>srge(n,0);
for(int i = 0; i < n; i++) srge[i]=i;
slv(srge);
vector<int>rt(n,0);
for(int i = 0; i < n; i++){
rt[to[i]]=i;
}
return rt;
}
Compilation message (stderr)
messy.cpp: In function 'void slv(std::vector<int>, int, int, std::string)':
messy.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i = 0; i < prge.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... |