#include "doll.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
void create_circuit(int m, vector<int> A){
int n = A.size();
if(n == 1){
answer({1, 0}, {}, {});
return;
}
int k = 1;
while(k < n) k*=2;
vector<int> sth(2*k, -2);
vector<pair<int, int>> candidates;
for(int i = k; i < 2*k; i++){
int j = i, pos = 0;
while(j != 1){
if(j&1) pos++;
pos<<=1;
j>>=1;
}
pos>>=1;
if(2*k-i-1 < n) candidates.pb({pos, i});
sth[i] = -1;
}
sort(candidates.begin(), candidates.end());
for(int i = 1; i < n; i++) sth[candidates[i-1].sc] = A[i];
sth[candidates.back().sc] = 0;
vector<int> C(m+1, -1), X, Y;
C[0] = A[0];
for(int i = k-1; i >= 1; i--){
if(sth[2*i] == -1 && sth[2*i+1] == -1) sth[i] = -1;
}
function<int(int)> rec = [&](int i){
X.pb(0), Y.pb(0);
int j = X.size();
if(sth[2*i] == -1) X[j-1] = -1;
else if(sth[2*i] >= 0) X[j-1] = sth[2*i];
else X[j-1] = rec(2*i);
if(sth[2*i+1] == -1) Y[j-1] = -1;
else if(sth[2*i+1] >= 0) Y[j-1] = sth[2*i+1];
else Y[j-1] = rec(2*i+1);
return -j;
};
rec(1);
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
27 ms |
5068 KB |
Output is correct |
3 |
Correct |
25 ms |
5384 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
1364 KB |
Output is correct |
6 |
Correct |
40 ms |
7332 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
27 ms |
5068 KB |
Output is correct |
3 |
Correct |
25 ms |
5384 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
1364 KB |
Output is correct |
6 |
Correct |
40 ms |
7332 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
45 ms |
7788 KB |
Output is correct |
9 |
Correct |
49 ms |
9492 KB |
Output is correct |
10 |
Correct |
73 ms |
12128 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
27 ms |
5068 KB |
Output is correct |
3 |
Correct |
25 ms |
5384 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
1364 KB |
Output is correct |
6 |
Correct |
40 ms |
7332 KB |
Output is correct |
7 |
Correct |
1 ms |
296 KB |
Output is correct |
8 |
Correct |
45 ms |
7788 KB |
Output is correct |
9 |
Correct |
49 ms |
9492 KB |
Output is correct |
10 |
Correct |
73 ms |
12128 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
77 ms |
11612 KB |
Output is correct |
15 |
Correct |
46 ms |
8488 KB |
Output is correct |
16 |
Correct |
71 ms |
11488 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
83 ms |
11912 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
40 ms |
7208 KB |
Output is correct |
3 |
Correct |
45 ms |
8352 KB |
Output is correct |
4 |
Correct |
69 ms |
11248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
40 ms |
7208 KB |
Output is correct |
3 |
Correct |
45 ms |
8352 KB |
Output is correct |
4 |
Correct |
69 ms |
11248 KB |
Output is correct |
5 |
Correct |
91 ms |
11384 KB |
Output is correct |
6 |
Correct |
69 ms |
11364 KB |
Output is correct |
7 |
Correct |
72 ms |
11376 KB |
Output is correct |
8 |
Correct |
72 ms |
11212 KB |
Output is correct |
9 |
Correct |
47 ms |
8268 KB |
Output is correct |
10 |
Correct |
67 ms |
11252 KB |
Output is correct |
11 |
Correct |
67 ms |
11180 KB |
Output is correct |
12 |
Correct |
43 ms |
8360 KB |
Output is correct |
13 |
Correct |
42 ms |
7316 KB |
Output is correct |
14 |
Correct |
44 ms |
8400 KB |
Output is correct |
15 |
Correct |
44 ms |
8396 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
45 ms |
7228 KB |
Output is correct |
18 |
Correct |
39 ms |
7292 KB |
Output is correct |
19 |
Correct |
42 ms |
8324 KB |
Output is correct |
20 |
Correct |
70 ms |
11300 KB |
Output is correct |
21 |
Correct |
66 ms |
11256 KB |
Output is correct |
22 |
Correct |
66 ms |
11208 KB |
Output is correct |