# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
75058 | dacin21 | Mechanical Doll (IOI18_doll) | C++14 | 143 ms | 12400 KiB |
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 bit_mirror(int A, int digits){
int ret = 0;
while(digits--){
ret = ret<<1 | (A&1);
A>>=1;
}
return ret;
}
void create_circuit(int M, vector<int> A){
const int lgn = __lg(2*A.size()-1);
const int N = 1<<lgn;
assert(N/2 < A.size() && A.size() <= N);
// remove surplus subtrees
vector<char> dead(2*N, 0);
int m = N - A.size();
for(int i=lgn, j=1;i>=0;--i,j=2*j){
if((m>>i)&1){
dead[j] = 1;
++j;
}
}
for(int i=1;i<N;++i){
if(dead[i]){
dead[2*i] = dead[2*i+1] = 1;
}
}
// assign leaves
A.push_back(0);
vector<int> leaves(N, -1);
for(int i=0, k=0;i<N;++i){
int j = bit_mirror(i, lgn);
if(!dead[N+j]){
leaves[j] = A[++k];
}
//cerr << i << " -> " << j << "\n";
}
// compress
vector<int> id(2*N, -1);
for(int i=2, j=-2;i<N;++i){
if(!dead[i]){
id[i] = j--;
}
}
for(int i=0;i<N;++i){
id[N+i] = leaves[i];
}
vector<int> C(M+1, 0);
C[0] = A[0];
for(int i=1;i<=M;++i){
C[i] = -1;
}
const int K = -*min_element(id.begin(), id.end());
vector<int> X(K), Y(K);
for(int i=0;i<N;++i){
if(!dead[i]){
X[-id[i]-1] = id[2*i];
Y[-id[i]-1] = id[2*i+1];
}
}
answer(C, X, Y);
}
Compilation message (stderr)
# | 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... |