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 "doll.h"
#include<bits/stdc++.h>
using namespace std;
int n;
int maxProf;
vector<int> X, Y;
int cnt = 0;
vector<pair<int, pair<int, int> > > aux;
int create();
int tree(int pai, int dir, int prof, int val, bool flag);
void create_circuit(int M, vector<int> A) {
n = A.size();
maxProf = log2(n + 1);
if(__builtin_popcount(n + 1) != 1) maxProf++;
vector<int> C (M + 1, -1);
tree(0, 0, 0, 0, 1);
sort(aux.begin(), aux.end());
for(int i = 0; i < aux.size(); i++){
if(aux[i].second.second) Y[aux[i].second.first] = A[i];
else X[aux[i].second.first] = A[i];
}
// for(int i = 0; i < X.size(); i++){
// printf("%d %d\n", -i - 1, X[i]);
// printf("%d %d\n", -i - 1, Y[i]);
// }
answer(C, X, Y);
}
int create(){
X.push_back(0);
Y.push_back(0);
return X.size() - 1;
}
int tree(int pai, int dir, int prof, int val, bool flag){
if(cnt >= n && !flag) return -1;
if(prof == maxProf){
if(flag) return 0;
cnt++;
aux.push_back(make_pair(val, make_pair(pai, dir)));
return -1;
}
int cur = create();
int eVal = val, dVal = val + (1 << prof);
int e = tree(cur, 0, prof + 1, eVal, 0);
X[cur] = e;
int d = tree(cur, 1, prof + 1, dVal, flag);
Y[cur] = d;
return -cur - 1;
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i = 0; i < aux.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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |