#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
typedef long long ll;
vector<int> C, X, Y, state;
int connect(int a, int bSize, int b, int orig = 0, int mask = 0, int bit = 0) {
if (!bit && orig) return b;
X.push_back(0);
Y.push_back(0);
int id = X.size() - 1;
bool first = false;
if (!orig) {
first = true;
orig = -X.size();
mask = bSize - 1;
if (mask == 0) {
X.pop_back();
Y.pop_back();
return b;
}
bit = 1 << (int)log2(mask);
}
if (mask & bit) {
X[id] = connect(a, bSize - (1 << ((int)log2(bSize) - 1)), b, orig, mask, bit >> 1);
Y[id] = connect(a, 1 << ((int)log2(bSize) - 1), b, orig, ~0, bit >> 1);
}
else {
X[id] = orig;
Y[id] = connect(a, 1 << ((int)log2(bSize) - 1), b, orig, mask, bit >> 1);
}
if (first) {
Y[X.size() - 1] = 0;
}
return -id - 1;
}
void create_circuit(int M, vector<int> A) {
A.push_back(0);
C = vector<int>(M + 1);
X = vector<int>(); Y = vector<int>();
vector<vector<int>> adj(M + 1);
int prev = 0;
for(auto &e : A) {
adj[prev].push_back(e);
prev = e;
}
C[0] = connect(0, A.size(), 1);
for (int i = 1; i < adj.size(); i++) {
C[i] = C[0];
}
state = vector<int>(X.size());
int pos = 0;
for (int i = 0; i < A.size(); i++) {
int prev = pos;
do {
prev = pos;
if (pos >= 0) {
pos = C[pos];
}
else {
pos = state[-pos - 1] ? Y[-pos - 1] : X[-pos - 1];
state[-prev - 1] = !state[-prev - 1];
}
} while (pos < 0);
if (pos != A[i]) {
(!state[-prev - 1] ? Y[-prev - 1] : X[-prev - 1]) = A[i];
pos = A[i];
}
}
answer(C, X, Y);
return;
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:55:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 1; i < adj.size(); i++) {
| ~~^~~~~~~~~~~~
doll.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < A.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
8860 KB |
Output is correct |
3 |
Correct |
33 ms |
7968 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
3932 KB |
Output is correct |
6 |
Correct |
48 ms |
11216 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
8860 KB |
Output is correct |
3 |
Correct |
33 ms |
7968 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
3932 KB |
Output is correct |
6 |
Correct |
48 ms |
11216 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
59 ms |
10108 KB |
Output is correct |
9 |
Correct |
63 ms |
12216 KB |
Output is correct |
10 |
Correct |
92 ms |
15356 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
33 ms |
8860 KB |
Output is correct |
3 |
Correct |
33 ms |
7968 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
8 ms |
3932 KB |
Output is correct |
6 |
Correct |
48 ms |
11216 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
59 ms |
10108 KB |
Output is correct |
9 |
Correct |
63 ms |
12216 KB |
Output is correct |
10 |
Correct |
92 ms |
15356 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
436 KB |
Output is correct |
14 |
Correct |
87 ms |
13848 KB |
Output is correct |
15 |
Correct |
65 ms |
8512 KB |
Output is correct |
16 |
Correct |
86 ms |
12964 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
91 ms |
14296 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
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 |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 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 |
432 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
54 ms |
7496 KB |
Output is correct |
3 |
Correct |
52 ms |
6504 KB |
Output is correct |
4 |
Correct |
81 ms |
10020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
54 ms |
7496 KB |
Output is correct |
3 |
Correct |
52 ms |
6504 KB |
Output is correct |
4 |
Correct |
81 ms |
10020 KB |
Output is correct |
5 |
Correct |
88 ms |
13548 KB |
Output is correct |
6 |
Correct |
82 ms |
13620 KB |
Output is correct |
7 |
Correct |
89 ms |
13868 KB |
Output is correct |
8 |
Correct |
79 ms |
12852 KB |
Output is correct |
9 |
Correct |
50 ms |
7244 KB |
Output is correct |
10 |
Correct |
77 ms |
12592 KB |
Output is correct |
11 |
Correct |
72 ms |
12340 KB |
Output is correct |
12 |
Correct |
53 ms |
8400 KB |
Output is correct |
13 |
Correct |
56 ms |
8820 KB |
Output is correct |
14 |
Correct |
59 ms |
9180 KB |
Output is correct |
15 |
Correct |
57 ms |
8772 KB |
Output is correct |
16 |
Correct |
2 ms |
600 KB |
Output is correct |
17 |
Correct |
46 ms |
8076 KB |
Output is correct |
18 |
Correct |
49 ms |
7736 KB |
Output is correct |
19 |
Correct |
48 ms |
7796 KB |
Output is correct |
20 |
Correct |
75 ms |
11976 KB |
Output is correct |
21 |
Correct |
80 ms |
11964 KB |
Output is correct |
22 |
Correct |
73 ms |
11380 KB |
Output is correct |