#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
void arrangeEndpoints(vi &endpoints)
{
if (endpoints.size() == 2)
return;
vi half1, half2;
for (int i = 0; i < endpoints.size(); i++)
{
if (i % 2 == 0)
half1.push_back(endpoints[i]);
else
half2.push_back(endpoints[i]);
}
arrangeEndpoints(half1);
arrangeEndpoints(half2);
endpoints.clear();
for (int x : half1)
endpoints.push_back(x);
for (int x : half2)
endpoints.push_back(x);
}
void create_circuit(int M, vi A)
{
int N = A.size(), S = 0;
A.push_back(0);
vi C(M + 1, 0), X, Y;
auto addSwitch = [&S, &X, &Y](int x, int y)
{
S++;
X.push_back(x);
Y.push_back(y);
return -S;
};
auto buildSwitchTree = [&S, &C, &X, &Y, &addSwitch](int trigger, vi &endpoints)
{
if (endpoints.size() == 1)
return C[trigger] = endpoints[0];
if (endpoints.size() == 2)
return C[trigger] = addSwitch(endpoints[0], endpoints[1]);
// treeSize = power2*2 - 1
// tree Ids in [1, power2*2 - 1]
// switch Ids in [S + 1, S + power2*2 - 1]
int power2 = 1;
while (power2 < endpoints.size())
power2 *= 2;
while (endpoints.size() < power2)
{
endpoints.push_back(-(S + 1));
swap(endpoints.back(), endpoints[endpoints.size() - 2]);
}
arrangeEndpoints(endpoints);
C[trigger] = -(S + 1);
for (int i = 1; i <= power2 - 1; i++)
{
int left = i * 2, right = i * 2 + 1;
if (right <= power2 - 1)
{
X.push_back(-(S + left));
Y.push_back(-(S + right));
}
else
{
left -= power2;
right -= power2;
X.push_back(endpoints[left]);
Y.push_back(endpoints[right]);
}
}
S += power2 - 1;
return 0;
};
vvi toMap(M + 1, vi(0));
toMap[0].push_back(A[0]);
for (int i = 0; i < N; i++)
toMap[A[i]].push_back(A[i + 1]);
for (int trg = 0; trg <= M; trg++)
{
vi &endpoints = toMap[trg];
if (endpoints.size() != 0)
buildSwitchTree(trg, endpoints);
}
answer(C, X, Y);
}
/*
int main()
{
create_circuit(3, {3, 3, 1, 3, 2});
}
*/
Compilation message
doll.cpp: In function 'void arrangeEndpoints(vi&)':
doll.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for (int i = 0; i < endpoints.size(); i++)
| ~~^~~~~~~~~~~~~~~~~~
doll.cpp: In lambda function:
doll.cpp:54:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | while (power2 < endpoints.size())
| ~~~~~~~^~~~~~~~~~~~~~~~~~
doll.cpp:56:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
56 | while (endpoints.size() < power2)
| ~~~~~~~~~~~~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
23 ms |
6772 KB |
Output is correct |
3 |
Correct |
25 ms |
5536 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
3796 KB |
Output is correct |
6 |
Correct |
29 ms |
8388 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
23 ms |
6772 KB |
Output is correct |
3 |
Correct |
25 ms |
5536 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
3796 KB |
Output is correct |
6 |
Correct |
29 ms |
8388 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
47 ms |
8192 KB |
Output is correct |
9 |
Correct |
44 ms |
9416 KB |
Output is correct |
10 |
Correct |
86 ms |
12196 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
23 ms |
6772 KB |
Output is correct |
3 |
Correct |
25 ms |
5536 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
3796 KB |
Output is correct |
6 |
Correct |
29 ms |
8388 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
47 ms |
8192 KB |
Output is correct |
9 |
Correct |
44 ms |
9416 KB |
Output is correct |
10 |
Correct |
86 ms |
12196 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
82 ms |
11856 KB |
Output is correct |
15 |
Correct |
48 ms |
7088 KB |
Output is correct |
16 |
Correct |
77 ms |
10140 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
296 KB |
Output is correct |
20 |
Correct |
75 ms |
12092 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
2 |
Correct |
64 ms |
7244 KB |
Output is correct |
3 |
Partially correct |
101 ms |
10456 KB |
Output is partially correct |
4 |
Partially correct |
109 ms |
11532 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
212 KB |
Output is partially correct |
2 |
Correct |
64 ms |
7244 KB |
Output is correct |
3 |
Partially correct |
101 ms |
10456 KB |
Output is partially correct |
4 |
Partially correct |
109 ms |
11532 KB |
Output is partially correct |
5 |
Partially correct |
142 ms |
13572 KB |
Output is partially correct |
6 |
Partially correct |
130 ms |
14140 KB |
Output is partially correct |
7 |
Partially correct |
114 ms |
13952 KB |
Output is partially correct |
8 |
Partially correct |
126 ms |
14256 KB |
Output is partially correct |
9 |
Partially correct |
102 ms |
10288 KB |
Output is partially correct |
10 |
Partially correct |
141 ms |
15148 KB |
Output is partially correct |
11 |
Partially correct |
140 ms |
14620 KB |
Output is partially correct |
12 |
Partially correct |
101 ms |
10228 KB |
Output is partially correct |
13 |
Partially correct |
98 ms |
9152 KB |
Output is partially correct |
14 |
Partially correct |
80 ms |
8992 KB |
Output is partially correct |
15 |
Partially correct |
68 ms |
8856 KB |
Output is partially correct |
16 |
Partially correct |
4 ms |
600 KB |
Output is partially correct |
17 |
Partially correct |
79 ms |
7972 KB |
Output is partially correct |
18 |
Partially correct |
71 ms |
8060 KB |
Output is partially correct |
19 |
Partially correct |
79 ms |
8612 KB |
Output is partially correct |
20 |
Partially correct |
99 ms |
11348 KB |
Output is partially correct |
21 |
Partially correct |
144 ms |
13128 KB |
Output is partially correct |
22 |
Partially correct |
111 ms |
10772 KB |
Output is partially correct |