#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
int N, cnter = 0;
vector<int> adj[100001];
vector<int> X(400002), Y(400002);
vector<int> C(200002);
void build(int a, int cur, int pa, int val, int bit){
if((1 << (bit + 1)) > adj[a].size() - 1){
if(adj[a].size() - 1 >= (val | (1 << bit))){
X[abs(cur)] = adj[a][val] == -1000000 ? pa : adj[a][val];
Y[abs(cur)] = adj[a][val | (1 << bit)] == -1000000 ? pa : adj[a][val | (1 << bit)];
}
else{
X[abs(cur)] = cur;
Y[abs(cur)] = adj[a][val] == -1000000 ? pa : adj[a][val];
}
return;
}
if(adj[a].size() - 1 >= (val | (1 << bit))){
X[abs(cur)] = --cnter;
build(a, cnter, cur, val, bit + 1);
Y[abs(cur)] = --cnter;
build(a, cnter, pa, val | (1 << bit), bit + 1);
}
else{
X[abs(cur)] = cur;
Y[abs(cur)] = --cnter;
build(a, cnter, pa, val, bit + 1);
}
}
void create_circuit(int M, vector<int> A) {
N = A.size();
for(int i = 0; i < N - 1; i++) adj[A[i]].push_back(A[i + 1]);
adj[A[N - 1]].push_back(0);
C[0] = A[0];
for(int i = 1; i <= M; i++){
if(adj[i].size() == 0) continue;
if(adj[i].size() == 1) C[i] = adj[i][0];
else{
C[i] = --cnter;
int j = 0;
for(; j <= 20; j++){
if((1 << j) >= adj[i].size()) break;
}
vector<int> tmp;
for(int k = 0; k < (1 << j) - adj[i].size(); k++) tmp.push_back(-1000000);
for(auto x : adj[i]) tmp.push_back(x);
adj[i] = tmp;
build(i, cnter, cnter, 0, 0);
}
}
vector<int> CA, XA, YA;
for(int i = 1; i <= abs(cnter); i++){
XA.push_back(X[i]); YA.push_back(Y[i]);
}
for(int i = 0; i <= M; i++) CA.push_back(C[i]);
answer(CA, XA, YA);
}
Compilation message
doll.cpp: In function 'void build(int, int, int, int, int)':
doll.cpp:10:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | if((1 << (bit + 1)) > adj[a].size() - 1){
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp:11:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
11 | if(adj[a].size() - 1 >= (val | (1 << bit))){
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
doll.cpp:22:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
22 | if(adj[a].size() - 1 >= (val | (1 << bit))){
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | if((1 << j) >= adj[i].size()) break;
| ~~~~~~~~~^~~~~~~~~~~~~~~~
doll.cpp:51:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int k = 0; k < (1 << j) - adj[i].size(); k++) tmp.push_back(-1000000);
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
26 ms |
10836 KB |
Output is correct |
3 |
Correct |
20 ms |
10364 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
12 ms |
7884 KB |
Output is correct |
6 |
Correct |
33 ms |
12452 KB |
Output is correct |
7 |
Correct |
4 ms |
6528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
26 ms |
10836 KB |
Output is correct |
3 |
Correct |
20 ms |
10364 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
12 ms |
7884 KB |
Output is correct |
6 |
Correct |
33 ms |
12452 KB |
Output is correct |
7 |
Correct |
4 ms |
6528 KB |
Output is correct |
8 |
Correct |
55 ms |
12868 KB |
Output is correct |
9 |
Correct |
53 ms |
13400 KB |
Output is correct |
10 |
Correct |
76 ms |
16292 KB |
Output is correct |
11 |
Correct |
5 ms |
6484 KB |
Output is correct |
12 |
Correct |
4 ms |
6580 KB |
Output is correct |
13 |
Correct |
3 ms |
6580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
26 ms |
10836 KB |
Output is correct |
3 |
Correct |
20 ms |
10364 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
12 ms |
7884 KB |
Output is correct |
6 |
Correct |
33 ms |
12452 KB |
Output is correct |
7 |
Correct |
4 ms |
6528 KB |
Output is correct |
8 |
Correct |
55 ms |
12868 KB |
Output is correct |
9 |
Correct |
53 ms |
13400 KB |
Output is correct |
10 |
Correct |
76 ms |
16292 KB |
Output is correct |
11 |
Correct |
5 ms |
6484 KB |
Output is correct |
12 |
Correct |
4 ms |
6580 KB |
Output is correct |
13 |
Correct |
3 ms |
6580 KB |
Output is correct |
14 |
Correct |
108 ms |
17332 KB |
Output is correct |
15 |
Correct |
51 ms |
12388 KB |
Output is correct |
16 |
Correct |
70 ms |
15252 KB |
Output is correct |
17 |
Correct |
3 ms |
6484 KB |
Output is correct |
18 |
Correct |
4 ms |
6584 KB |
Output is correct |
19 |
Correct |
4 ms |
6500 KB |
Output is correct |
20 |
Correct |
80 ms |
16676 KB |
Output is correct |
21 |
Correct |
3 ms |
6484 KB |
Output is correct |
22 |
Correct |
3 ms |
6588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
6484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
6484 KB |
Output is partially correct |
2 |
Correct |
41 ms |
13148 KB |
Output is correct |
3 |
Partially correct |
94 ms |
18708 KB |
Output is partially correct |
4 |
Incorrect |
91 ms |
19204 KB |
wrong motion |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
6484 KB |
Output is partially correct |
2 |
Correct |
41 ms |
13148 KB |
Output is correct |
3 |
Partially correct |
94 ms |
18708 KB |
Output is partially correct |
4 |
Incorrect |
91 ms |
19204 KB |
wrong motion |
5 |
Halted |
0 ms |
0 KB |
- |