#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
struct node {
int l = -1, r = -1, y = 0;
};
int timer = 2, dep;
vector<int> x, y;
node tree[200005];
void build(int n, int d) {
if (dep-1 == d) {
return;
}
tree[n].l = -timer;
timer++;
tree[n].r = -timer;
timer++;
build(-tree[n].l, d+1);
build(-tree[n].r, d+1);
}
void create(int n, int d, int v) {
if (dep-1 == d) {
if (tree[n].y == 0) {
tree[n].l = v;
} else {
tree[n].r = v;
}
} else {
if (tree[n].y == 0) {
create(-tree[n].l, d+1, v);
} else {
create(-tree[n].r, d+1, v);
}
}
tree[n].y ^= 1;
}
void create_circuit(int m, vector<int> a) {
vector<int> d(m+1, -1);
d[0] = a[0];
int n = a.size(), s;
dep = ceil(log2(n));
cout << dep << endl;
s = 1 << dep;
build(1, 0);
for (int i = 1; i < s; i++) {
if (i < a.size()) {
create(1, 0, a[i]);
} else {
create(1, 0, -1);
}
}
create(1, 0, 0);
for (int i = 1; i < s; i++) {
x.push_back(tree[i].l);
y.push_back(tree[i].r);
}
answer(d, x, y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:46:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if (i < a.size()) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
DO NOT PRINT ANYTHING TO STANDARD OUTPUT |
2 |
Halted |
0 ms |
0 KB |
- |