#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[500005];
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, 0);
a.push_back(0);
vector<set<int>> edges(m+1);
d[0] = a.front();
for (int i = 1; i < a.size(); i++) {
edges[a[i-1]].insert(a[i]);
}
a.pop_back();
vector<int> c;
for (int i = 0; i < a.size(); i++) {
if (edges[a[i]].size() == 0) {
d[a[i]] = 0;
} else if (edges[a[i]].size() == 1) {
d[a[i]] = *edges[a[i]].begin();
} else {
d[a[i]] = -1;
c.push_back(a[i]);
}
}
a = c;
if (!a.empty()) {
int n = a.size(), s;
dep = ceil(log2(n));
s = 1 << dep;
build(1, 0);
for (int i = 1; i < s; i++) {
if (i < n) {
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:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 1; i < a.size(); i++) {
| ~~^~~~~~~~~~
doll.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
18 ms |
9816 KB |
Output is correct |
3 |
Correct |
15 ms |
7768 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
6236 KB |
Output is correct |
6 |
Correct |
25 ms |
11728 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
18 ms |
9816 KB |
Output is correct |
3 |
Correct |
15 ms |
7768 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
6236 KB |
Output is correct |
6 |
Correct |
25 ms |
11728 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
68 ms |
16720 KB |
wrong motion |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
18 ms |
9816 KB |
Output is correct |
3 |
Correct |
15 ms |
7768 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
10 ms |
6236 KB |
Output is correct |
6 |
Correct |
25 ms |
11728 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Incorrect |
68 ms |
16720 KB |
wrong motion |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
wrong motion |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
47 ms |
8008 KB |
Output is correct |
3 |
Partially correct |
90 ms |
11132 KB |
Output is partially correct |
4 |
Partially correct |
93 ms |
12272 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
47 ms |
8008 KB |
Output is correct |
3 |
Partially correct |
90 ms |
11132 KB |
Output is partially correct |
4 |
Partially correct |
93 ms |
12272 KB |
Output is partially correct |
5 |
Partially correct |
135 ms |
23616 KB |
Output is partially correct |
6 |
Partially correct |
137 ms |
22852 KB |
Output is partially correct |
7 |
Partially correct |
135 ms |
23104 KB |
Output is partially correct |
8 |
Partially correct |
142 ms |
22908 KB |
Output is partially correct |
9 |
Partially correct |
92 ms |
11260 KB |
Output is partially correct |
10 |
Incorrect |
110 ms |
15896 KB |
wrong motion |
11 |
Halted |
0 ms |
0 KB |
- |