#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);
vector<int> ord;
bitset<1500000> mark;
void chk(int a, int vv, int val, int bit){
if((1 << (bit + 1)) > adj[a].size() - 1){
ord.push_back(val); ord.push_back(val | (1 << bit));
return;
}
chk(a, vv * 2, val, bit + 1);
chk(a, vv * 2 + 1, val | (1 << bit), bit + 1);
}
void rechk(int a, int vv, int val, int bit){
if((1 << (bit + 1)) > adj[a].size() - 1){
if(adj[a][val] == -1) mark[vv * 2] = 1; else mark[vv * 2] = 0;
if(adj[a][val | (1 << bit)] == -1) mark[vv * 2 + 1] = 1; else mark[vv * 2 + 1] = 0;
mark[vv] = mark[vv * 2] & mark[vv * 2 + 1];
return;
}
rechk(a, vv * 2, val, bit + 1);
rechk(a, vv * 2 + 1, val | (1 << bit), bit + 1);
mark[vv] = mark[vv * 2] & mark[vv * 2 + 1];
}
void build(int a, int vv, int cur, int pa, int val, int bit){
if((1 << (bit + 1)) > adj[a].size() - 1){
X[abs(cur)] = adj[a][val] == -1 ? pa : adj[a][val];
Y[abs(cur)] = adj[a][val | (1 << bit)] == -1 ? pa : adj[a][val | (1 << bit)];
return;
}
if(mark[vv * 2]){
X[abs(cur)] = pa;
Y[abs(cur)] = --cnter;
build(a, vv * 2 + 1, cnter, pa, val | (1 << bit), bit + 1);
}
else if(mark[vv * 2 + 1]){
X[abs(cur)] = pa;
Y[abs(cur)] = --cnter;
build(a, vv * 2, cnter, pa, val, bit + 1);
}
else{
X[abs(cur)] = --cnter;
build(a, vv * 2, cnter, pa, val, bit + 1);
Y[abs(cur)] = --cnter;
build(a, vv * 2 + 1, cnter, pa, val | (1 << bit), 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((1 << j), 0);
chk(i, 1, 0, 0);
for(int k = 0; k < (1 << j) - adj[i].size(); k++) tmp[ord[k]] = -1;
int idx = 0;
for(auto x : adj[i]){
while(tmp[idx] == -1) idx++;
tmp[idx] = x;
idx++;
}
adj[i] = tmp; rechk(i, 1, 0, 0);
build(i, 1, cnter, cnter, 0, 0);
ord.clear();
}
}
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 chk(int, int, int, int)':
doll.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | if((1 << (bit + 1)) > adj[a].size() - 1){
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp: In function 'void rechk(int, int, int, int)':
doll.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if((1 << (bit + 1)) > adj[a].size() - 1){
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp: In function 'void build(int, int, int, int, int, int)':
doll.cpp:37:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | if((1 << (bit + 1)) > adj[a].size() - 1){
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:74:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if((1 << j) >= adj[i].size()) break;
| ~~~~~~~~~^~~~~~~~~~~~~~~~
doll.cpp:79:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int k = 0; k < (1 << j) - adj[i].size(); k++) tmp[ord[k]] = -1;
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
29 ms |
10568 KB |
Output is correct |
3 |
Correct |
33 ms |
10032 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
11 ms |
7856 KB |
Output is correct |
6 |
Correct |
30 ms |
11844 KB |
Output is correct |
7 |
Correct |
3 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
29 ms |
10568 KB |
Output is correct |
3 |
Correct |
33 ms |
10032 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
11 ms |
7856 KB |
Output is correct |
6 |
Correct |
30 ms |
11844 KB |
Output is correct |
7 |
Correct |
3 ms |
6484 KB |
Output is correct |
8 |
Correct |
54 ms |
12196 KB |
Output is correct |
9 |
Correct |
51 ms |
12780 KB |
Output is correct |
10 |
Correct |
77 ms |
15168 KB |
Output is correct |
11 |
Correct |
4 ms |
6580 KB |
Output is correct |
12 |
Correct |
4 ms |
6588 KB |
Output is correct |
13 |
Correct |
3 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
29 ms |
10568 KB |
Output is correct |
3 |
Correct |
33 ms |
10032 KB |
Output is correct |
4 |
Correct |
3 ms |
6484 KB |
Output is correct |
5 |
Correct |
11 ms |
7856 KB |
Output is correct |
6 |
Correct |
30 ms |
11844 KB |
Output is correct |
7 |
Correct |
3 ms |
6484 KB |
Output is correct |
8 |
Correct |
54 ms |
12196 KB |
Output is correct |
9 |
Correct |
51 ms |
12780 KB |
Output is correct |
10 |
Correct |
77 ms |
15168 KB |
Output is correct |
11 |
Correct |
4 ms |
6580 KB |
Output is correct |
12 |
Correct |
4 ms |
6588 KB |
Output is correct |
13 |
Correct |
3 ms |
6484 KB |
Output is correct |
14 |
Correct |
91 ms |
16156 KB |
Output is correct |
15 |
Correct |
49 ms |
11616 KB |
Output is correct |
16 |
Correct |
69 ms |
14116 KB |
Output is correct |
17 |
Correct |
3 ms |
6484 KB |
Output is correct |
18 |
Correct |
4 ms |
6484 KB |
Output is correct |
19 |
Correct |
3 ms |
6484 KB |
Output is correct |
20 |
Correct |
75 ms |
15472 KB |
Output is correct |
21 |
Correct |
3 ms |
6572 KB |
Output is correct |
22 |
Correct |
4 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
3 ms |
6484 KB |
Output is correct |
3 |
Correct |
3 ms |
6584 KB |
Output is correct |
4 |
Correct |
3 ms |
6520 KB |
Output is correct |
5 |
Correct |
3 ms |
6468 KB |
Output is correct |
6 |
Correct |
3 ms |
6484 KB |
Output is correct |
7 |
Correct |
3 ms |
6484 KB |
Output is correct |
8 |
Correct |
4 ms |
6484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
42 ms |
13016 KB |
Output is correct |
3 |
Correct |
46 ms |
14016 KB |
Output is correct |
4 |
Correct |
67 ms |
17836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6484 KB |
Output is correct |
2 |
Correct |
42 ms |
13016 KB |
Output is correct |
3 |
Correct |
46 ms |
14016 KB |
Output is correct |
4 |
Correct |
67 ms |
17836 KB |
Output is correct |
5 |
Partially correct |
91 ms |
17876 KB |
Output is partially correct |
6 |
Partially correct |
85 ms |
17552 KB |
Output is partially correct |
7 |
Partially correct |
89 ms |
17532 KB |
Output is partially correct |
8 |
Partially correct |
99 ms |
17120 KB |
Output is partially correct |
9 |
Partially correct |
45 ms |
12984 KB |
Output is partially correct |
10 |
Partially correct |
83 ms |
16948 KB |
Output is partially correct |
11 |
Partially correct |
72 ms |
16276 KB |
Output is partially correct |
12 |
Partially correct |
48 ms |
12796 KB |
Output is partially correct |
13 |
Partially correct |
57 ms |
13736 KB |
Output is partially correct |
14 |
Partially correct |
57 ms |
13748 KB |
Output is partially correct |
15 |
Partially correct |
61 ms |
13916 KB |
Output is partially correct |
16 |
Partially correct |
5 ms |
6740 KB |
Output is partially correct |
17 |
Partially correct |
48 ms |
12516 KB |
Output is partially correct |
18 |
Partially correct |
45 ms |
12352 KB |
Output is partially correct |
19 |
Partially correct |
48 ms |
12564 KB |
Output is partially correct |
20 |
Partially correct |
70 ms |
15712 KB |
Output is partially correct |
21 |
Partially correct |
64 ms |
15928 KB |
Output is partially correct |
22 |
Partially correct |
70 ms |
15544 KB |
Output is partially correct |