#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
void create_circuit(int M, vector<int> A) {
int N, cur = 0;
vector<int> C(M + 1, -1), X, Y;
A.emplace_back(0), N = A.size();
auto rec = [&](auto rec, int sz, int dep)->int {
cur++;
int pos = -cur, i = -(pos + 1);
X.emplace_back(-1), Y.emplace_back(-1);
if (dep == 0) {
if (sz == 1) Y[i] = 0;
if (sz == 2) X[i] = Y[i] = 0;
return pos;
}
int half = 1 << dep;
if (sz <= half) Y[i] = rec(rec, sz, dep - 1);
else {
X[i] = rec(rec, sz - half, dep - 1);
Y[i] = rec(rec, half, dep - 1);
}
return pos;
};
rec(rec, N, __lg(N - 1));
vector<int> b(cur, 0);
int p = 0, pos = -1;
while (p < N) {
int i = -(pos + 1);
if (b[i] == 0) {
if (X[i] == 0) X[i] = A[p++], pos = -1;
else pos = X[i];
} else {
if (Y[i] == 0) Y[i] = A[p++], pos = -1;
else pos = Y[i];
}
b[i] ^= 1;
}
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
4008 KB |
Output is correct |
3 |
Correct |
28 ms |
3772 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
1364 KB |
Output is correct |
6 |
Correct |
47 ms |
5492 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
4008 KB |
Output is correct |
3 |
Correct |
28 ms |
3772 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
1364 KB |
Output is correct |
6 |
Correct |
47 ms |
5492 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
62 ms |
5792 KB |
Output is correct |
9 |
Correct |
60 ms |
6108 KB |
Output is correct |
10 |
Correct |
85 ms |
8736 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
4008 KB |
Output is correct |
3 |
Correct |
28 ms |
3772 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
1364 KB |
Output is correct |
6 |
Correct |
47 ms |
5492 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
62 ms |
5792 KB |
Output is correct |
9 |
Correct |
60 ms |
6108 KB |
Output is correct |
10 |
Correct |
85 ms |
8736 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
82 ms |
8384 KB |
Output is correct |
15 |
Correct |
57 ms |
5416 KB |
Output is correct |
16 |
Correct |
83 ms |
8168 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
86 ms |
8436 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
51 ms |
4832 KB |
Output is correct |
3 |
Correct |
52 ms |
4948 KB |
Output is correct |
4 |
Correct |
78 ms |
7236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
51 ms |
4832 KB |
Output is correct |
3 |
Correct |
52 ms |
4948 KB |
Output is correct |
4 |
Correct |
78 ms |
7236 KB |
Output is correct |
5 |
Correct |
87 ms |
8000 KB |
Output is correct |
6 |
Correct |
83 ms |
7804 KB |
Output is correct |
7 |
Correct |
80 ms |
7984 KB |
Output is correct |
8 |
Correct |
90 ms |
7616 KB |
Output is correct |
9 |
Correct |
49 ms |
4948 KB |
Output is correct |
10 |
Correct |
78 ms |
7564 KB |
Output is correct |
11 |
Correct |
76 ms |
7244 KB |
Output is correct |
12 |
Correct |
55 ms |
4940 KB |
Output is correct |
13 |
Correct |
55 ms |
5224 KB |
Output is correct |
14 |
Correct |
58 ms |
5316 KB |
Output is correct |
15 |
Correct |
53 ms |
5412 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
51 ms |
6096 KB |
Output is correct |
18 |
Correct |
51 ms |
4928 KB |
Output is correct |
19 |
Correct |
50 ms |
4804 KB |
Output is correct |
20 |
Correct |
79 ms |
7408 KB |
Output is correct |
21 |
Correct |
80 ms |
7256 KB |
Output is correct |
22 |
Correct |
79 ms |
7356 KB |
Output is correct |