#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "/home/ioi/contests/ioi18_d2/debug.h"
#else
#define debug(...) void(37)
#endif
void create_circuit(int M, std::vector<int> A) {
A.push_back(0);
int N = A.size();
/*
std::vector<int> C(M + 1);
C[0] = -1;
for (int i = 1; i <= M; ++i) {
C[i] = 1;
}
std::vector<int> X(N), Y(N);
for (int k = 0; k < N; ++k) {
X[k] = Y[k] = A[k];
}
answer(C, X, Y);
*/
int S = 1;
while (S < N) {
S *= 2;
}
vector<int> X, Y;
auto Dfs = [&](int l, int r, auto&& Dfs) {
if (S - r > N) {
return -1;
}
if (l == r) {
return 0;
}
int mid = (l + r) / 2;
int v = int(X.size());
X.push_back(-1);
Y.push_back(-1);
int left = Dfs(l, mid, Dfs);
int right = Dfs(mid + 1, r, Dfs);
X[v] = left, Y[v] = right;
return -1 - v;
};
Dfs(0, S - 1, Dfs);
int n = int(X.size());
vector<int> p(n);
for (int i = 0; i < N; ++i) {
int v = 0;
while (true) {
int to = (p[v] ? Y[v] : X[v]);
p[v] ^= 1;
if (to == 0) {
break;
}
v = -to - 1;
}
(p[v] ? X[v] : Y[v]) = A[i];
}
answer(vector<int>(M + 1, -1), X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
27 ms |
4296 KB |
Output is correct |
3 |
Correct |
25 ms |
4420 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1116 KB |
Output is correct |
6 |
Correct |
37 ms |
6308 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
27 ms |
4296 KB |
Output is correct |
3 |
Correct |
25 ms |
4420 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1116 KB |
Output is correct |
6 |
Correct |
37 ms |
6308 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
54 ms |
6768 KB |
Output is correct |
9 |
Correct |
53 ms |
7008 KB |
Output is correct |
10 |
Correct |
75 ms |
10196 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
27 ms |
4296 KB |
Output is correct |
3 |
Correct |
25 ms |
4420 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
6 ms |
1116 KB |
Output is correct |
6 |
Correct |
37 ms |
6308 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
54 ms |
6768 KB |
Output is correct |
9 |
Correct |
53 ms |
7008 KB |
Output is correct |
10 |
Correct |
75 ms |
10196 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
82 ms |
9736 KB |
Output is correct |
15 |
Correct |
51 ms |
6256 KB |
Output is correct |
16 |
Correct |
72 ms |
9736 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
107 ms |
9948 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 |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
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 |
67 ms |
5756 KB |
Output is correct |
3 |
Correct |
50 ms |
5744 KB |
Output is correct |
4 |
Correct |
76 ms |
8768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
67 ms |
5756 KB |
Output is correct |
3 |
Correct |
50 ms |
5744 KB |
Output is correct |
4 |
Correct |
76 ms |
8768 KB |
Output is correct |
5 |
Correct |
69 ms |
9592 KB |
Output is correct |
6 |
Correct |
72 ms |
9416 KB |
Output is correct |
7 |
Correct |
71 ms |
9480 KB |
Output is correct |
8 |
Correct |
76 ms |
9028 KB |
Output is correct |
9 |
Correct |
47 ms |
5752 KB |
Output is correct |
10 |
Correct |
72 ms |
8996 KB |
Output is correct |
11 |
Correct |
67 ms |
8768 KB |
Output is correct |
12 |
Correct |
51 ms |
5748 KB |
Output is correct |
13 |
Correct |
51 ms |
6008 KB |
Output is correct |
14 |
Correct |
51 ms |
6504 KB |
Output is correct |
15 |
Correct |
72 ms |
6232 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
46 ms |
7244 KB |
Output is correct |
18 |
Correct |
51 ms |
5748 KB |
Output is correct |
19 |
Correct |
47 ms |
5752 KB |
Output is correct |
20 |
Correct |
78 ms |
8960 KB |
Output is correct |
21 |
Correct |
74 ms |
8700 KB |
Output is correct |
22 |
Correct |
76 ms |
8768 KB |
Output is correct |