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>
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
#include "messy.h"
ll N;
vector<int>permutation;
void llenar(int l, int r){
ll mid = (l+r)/2;
string ans = "";
for(int i = 0 ; i < N ; i++){
ans+="1";
}
for(int i = l ; i <= r ; i++){
ans[i] = '0';
}
for(int i = l ; i <= mid ; i++){
ans[i]='1';
add_element(ans);
ans[i]='0';
}
}
void recArbol(int l, int r){
if(l==r)return ;
llenar(l, r);
recArbol(l, (l+r)/2);
recArbol(((l+r)/2)+1, r);
}
struct messy
{
int dd, ht, mid;
vector<int>values;
messy *L, *R;
messy(int l, int r){
////cout<< l << " " << r << endl;
dd = l;
ht = r;
mid = (dd+ht)/2;
if(dd!=ht){
L = new messy(l, mid);
R = new messy(mid+1, r);
}
}
void addValues(int cual){
values.pb(cual);
//cout<<dd << " - " << ht << " added: " << cual << endl;
}
void ask(){
if(dd==ht){
permutation[values.back()] = dd;
return;
}
//cout<<"doing "<<dd<<" " << ht << endl;
string p = "";
for(int i = 0 ; i < N; i++){
p+="1";
}
for(int i = 0 ; i < values.size() ; i ++){
p[values[i]]='0';
}
for(int i = 0 ; i < values.size() ; i++){
p[values[i]]='1';
//cout<<"to test "<<p<<endl;
if(check_element(p)){
L->addValues(values[i]);
}else{
R->addValues(values[i]);
}
p[values[i]]='0';
}
L->ask();
R->ask();
}
};
messy *run;
std::vector<int> restore_permutation(int n, int w, int r) {
string s= "", k = "";
N = n;
recArbol(0, n-1);
compile_set();
permutation.resize(n);
run = new messy(0, N-1);
for(int i = 0 ; i < n ; i++)run->addValues(i);
run->ask();
return permutation;
}
Compilation message (stderr)
messy.cpp: In member function 'void messy::ask()':
messy.cpp:63:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i = 0 ; i < values.size() ; i ++){
| ~~^~~~~~~~~~~~~~~
messy.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int i = 0 ; i < values.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... |