#include "doll.h"
#include "bits/stdc++.h"
using namespace std;
void create_circuit(int m, vector<int> a) {
vector<int> c(m + 1, -1);
if((int)a.size() == 1) {
c.assign(m + 1, 0);
c[0] = a[0];
answer(c, {}, {});
return;
}
c[0] = a[0];
a.erase(a.begin());
a.push_back(0);
int n = a.size();
int x_ = __lg(n);
if((1 << x_) < n) x_++;
vector<int> x, y;
int last = 0;
auto get = [&](){
x.push_back(0);
y.push_back(0);
last++;
return last;
};
function<int(int, int, vector<int>)> buildTree = [&](int l, int r, vector<int> a){
if((int)a.size() == 0){
return -1;
}
if(l == r){
assert((int)a.size() == 1);
return 0;
}
int m = (l + r) >> 1;
int r_sz = min(r - m, (int)a.size());
int goLeft = (int)a.size() - r_sz;
vector<int> goL(goLeft), goR(r_sz);
int root = get();
x[root - 1] = buildTree(l, m, goL);
y[root - 1] = buildTree(m + 1, r, goR);
return -root;
};
buildTree(0, (1 << x_) - 1, a);
vector<int> dir(last, 0);
function<int(int, int)> simulate = [&](int root, int value){
if(root >= 0){
return value;
}
root = -root;
dir[root - 1] ^= 1;
if(dir[root - 1] != 0){
x[root - 1] = simulate(x[root - 1], value);
} else {
y[root - 1] = simulate(y[root - 1], value);
}
return -root;
};
for(int i=0;i<(int)a.size();i++){
simulate(-1, a[i]);
}
assert(last <= n + x_);
answer(c, x, y);
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
31 ms |
4436 KB |
Output is correct |
3 |
Correct |
36 ms |
3640 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1372 KB |
Output is correct |
6 |
Correct |
49 ms |
5092 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
31 ms |
4436 KB |
Output is correct |
3 |
Correct |
36 ms |
3640 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1372 KB |
Output is correct |
6 |
Correct |
49 ms |
5092 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
61 ms |
6828 KB |
Output is correct |
9 |
Correct |
68 ms |
7536 KB |
Output is correct |
10 |
Correct |
101 ms |
10756 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
31 ms |
4436 KB |
Output is correct |
3 |
Correct |
36 ms |
3640 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1372 KB |
Output is correct |
6 |
Correct |
49 ms |
5092 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
61 ms |
6828 KB |
Output is correct |
9 |
Correct |
68 ms |
7536 KB |
Output is correct |
10 |
Correct |
101 ms |
10756 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
364 KB |
Output is correct |
14 |
Correct |
100 ms |
10116 KB |
Output is correct |
15 |
Correct |
65 ms |
6984 KB |
Output is correct |
16 |
Correct |
102 ms |
9916 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
96 ms |
10280 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
60 ms |
5376 KB |
Output is correct |
3 |
Correct |
64 ms |
5960 KB |
Output is correct |
4 |
Correct |
96 ms |
7920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
60 ms |
5376 KB |
Output is correct |
3 |
Correct |
64 ms |
5960 KB |
Output is correct |
4 |
Correct |
96 ms |
7920 KB |
Output is correct |
5 |
Correct |
94 ms |
8200 KB |
Output is correct |
6 |
Correct |
95 ms |
8236 KB |
Output is correct |
7 |
Correct |
96 ms |
8228 KB |
Output is correct |
8 |
Correct |
99 ms |
8184 KB |
Output is correct |
9 |
Correct |
65 ms |
5960 KB |
Output is correct |
10 |
Correct |
106 ms |
7980 KB |
Output is correct |
11 |
Correct |
98 ms |
7584 KB |
Output is correct |
12 |
Correct |
61 ms |
5964 KB |
Output is correct |
13 |
Correct |
58 ms |
5544 KB |
Output is correct |
14 |
Correct |
69 ms |
6096 KB |
Output is correct |
15 |
Correct |
65 ms |
6104 KB |
Output is correct |
16 |
Correct |
2 ms |
612 KB |
Output is correct |
17 |
Correct |
57 ms |
5396 KB |
Output is correct |
18 |
Correct |
62 ms |
5292 KB |
Output is correct |
19 |
Correct |
63 ms |
5992 KB |
Output is correct |
20 |
Correct |
98 ms |
7956 KB |
Output is correct |
21 |
Correct |
93 ms |
7896 KB |
Output is correct |
22 |
Correct |
95 ms |
7888 KB |
Output is correct |