#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
int idd;
int n, m;
vector<int> a;
vector<int> state;
vector<int> c, x, y;
void build(int nd, int l, int r, int elements) {
assert(l != r);
int mid = (l + r) >> 1;
int sz = 1;
while (sz * 2 <= min(elements, r - mid)) {
sz *= 2;
}
if (mid + 1 < r) {
int rx = --idd;
x.push_back(0);
y.push_back(0);
y[-nd - 1] = rx;
build(rx, mid + 1, r, sz);
}
if (sz == elements) {
x[-nd - 1] = -1;
} else if (l < mid) {
int lx = --idd;
x.push_back(0);
y.push_back(0);
x[-nd - 1] = lx;
build(lx, l, mid, elements - sz);
}
}
void dfs(int v, int ptr) {
if (v == 0) {
return;
}
if (v > 0) {
dfs(c[v], ptr + 1);
} else {
if (state[-v - 1] == 0) {
if (!x[-v - 1]) {
x[-v - 1] = a[ptr];
}
state[-v - 1] ^= 1;
dfs(x[-v - 1], ptr);
} else {
if (!y[-v - 1]) {
y[-v - 1] = a[ptr];
}
state[-v - 1] ^= 1;
dfs(y[-v - 1], ptr);
}
}
}
void create_circuit(int m_, vector<int> a_) {
m = m_;
a = a_;
a.push_back(0);
n = (int) a.size();
idd = -1;
x.push_back(0);
y.push_back(0);
int b = 1;
while (b < n) {
b *= 2;
}
build(-1, 0, b - 1, n);
c.assign(m + 1, -1);
state.resize(-idd);
dfs(-1, 0);
if (-idd > (int) log2(n) + n) {
assert(n <= 12);
}
//assert(-idd <= (int) log2(n) + n);
answer(c, x, y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
4908 KB |
Output is correct |
3 |
Correct |
23 ms |
4808 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1492 KB |
Output is correct |
6 |
Runtime error |
31 ms |
6600 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
4908 KB |
Output is correct |
3 |
Correct |
23 ms |
4808 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1492 KB |
Output is correct |
6 |
Runtime error |
31 ms |
6600 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
24 ms |
4908 KB |
Output is correct |
3 |
Correct |
23 ms |
4808 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1492 KB |
Output is correct |
6 |
Runtime error |
31 ms |
6600 KB |
Execution killed with signal 6 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
42 ms |
6108 KB |
Output is correct |
3 |
Correct |
42 ms |
6260 KB |
Output is correct |
4 |
Runtime error |
57 ms |
11448 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
42 ms |
6108 KB |
Output is correct |
3 |
Correct |
42 ms |
6260 KB |
Output is correct |
4 |
Runtime error |
57 ms |
11448 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |