#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
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from doll.cpp:2:
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | assert(N/2 < A.size() && A.size() <= N);
| ~~~~^~~~~~~~~~
doll.cpp:17:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
17 | assert(N/2 < A.size() && A.size() <= N);
| ~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
58 ms |
4776 KB |
Output is correct |
3 |
Correct |
46 ms |
5320 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
18 ms |
1356 KB |
Output is correct |
6 |
Correct |
64 ms |
6836 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
58 ms |
4776 KB |
Output is correct |
3 |
Correct |
46 ms |
5320 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
18 ms |
1356 KB |
Output is correct |
6 |
Correct |
64 ms |
6836 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
67 ms |
7560 KB |
Output is correct |
9 |
Correct |
89 ms |
9768 KB |
Output is correct |
10 |
Correct |
103 ms |
12400 KB |
Output is correct |
11 |
Correct |
1 ms |
220 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
58 ms |
4776 KB |
Output is correct |
3 |
Correct |
46 ms |
5320 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
18 ms |
1356 KB |
Output is correct |
6 |
Correct |
64 ms |
6836 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
67 ms |
7560 KB |
Output is correct |
9 |
Correct |
89 ms |
9768 KB |
Output is correct |
10 |
Correct |
103 ms |
12400 KB |
Output is correct |
11 |
Correct |
1 ms |
220 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
14 |
Correct |
116 ms |
12012 KB |
Output is correct |
15 |
Correct |
60 ms |
9024 KB |
Output is correct |
16 |
Correct |
143 ms |
11900 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
2 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
130 ms |
12212 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
244 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
63 ms |
6832 KB |
Output is correct |
3 |
Correct |
78 ms |
8600 KB |
Output is correct |
4 |
Correct |
87 ms |
11232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
63 ms |
6832 KB |
Output is correct |
3 |
Correct |
78 ms |
8600 KB |
Output is correct |
4 |
Correct |
87 ms |
11232 KB |
Output is correct |
5 |
Correct |
101 ms |
11712 KB |
Output is correct |
6 |
Correct |
112 ms |
11512 KB |
Output is correct |
7 |
Correct |
135 ms |
11644 KB |
Output is correct |
8 |
Correct |
134 ms |
11440 KB |
Output is correct |
9 |
Correct |
86 ms |
8572 KB |
Output is correct |
10 |
Correct |
93 ms |
11384 KB |
Output is correct |
11 |
Correct |
87 ms |
11168 KB |
Output is correct |
12 |
Correct |
87 ms |
8628 KB |
Output is correct |
13 |
Correct |
66 ms |
6888 KB |
Output is correct |
14 |
Correct |
67 ms |
8892 KB |
Output is correct |
15 |
Correct |
84 ms |
8852 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
52 ms |
6832 KB |
Output is correct |
18 |
Correct |
50 ms |
6820 KB |
Output is correct |
19 |
Correct |
74 ms |
8640 KB |
Output is correct |
20 |
Correct |
122 ms |
11252 KB |
Output is correct |
21 |
Correct |
86 ms |
11160 KB |
Output is correct |
22 |
Correct |
83 ms |
11148 KB |
Output is correct |