#include "doll.h"
#include<vector>
#include<iostream>
#include<cassert>
#define MAXN 200105
using namespace std;
int N, L, V=-1, id;
bool state[MAXN];
vector<int> X, Y, C, Seq;
int build(int x, int d) {
if (x == 1 && d == 0) {
return(69);
} else if (x == 0) {return(-1);}
assert(d > 0);
int cur = V;
V--;
X[-cur-1] = build(x-min(x,(1<<(d-1))), d-1);
Y[-cur-1] = build(min(x,(1<<(d-1))), d-1);
return(cur);
}
int log(int x) {
return(x <= 1 ? 0 : log(x/2) + 1);
}
void simulate(int u) {
if (id == N+1) {return;}
if (state[-u] == 0) {
state[-u] = 1;
if (X[-u-1] == 69) {
X[-u-1] = Seq[id];
id++;
simulate(-1);
} else {
simulate(X[-u-1]);
}
} else {
state[-u] = 0;
if (Y[-u-1] == 69) {
Y[-u-1] = Seq[id];
id++;
simulate(-1);
} else {
simulate(Y[-u-1]);
}
}
}
void create_circuit(int M, std::vector<int> A) {
N = A.size(), L = log(N+1);
if ((1<<L) < N+1) {L++;}
for (int i=0; i<=M; i++) {
C.push_back(-1);
}
for (int i=0; i<N+L; i++) {
X.push_back(0);
Y.push_back(0);
}
Seq = A;
Seq.push_back(0);
build(N+1, L);
while (X.back() == 0 && Y.back() == 0) {
X.pop_back();
Y.pop_back();
}
simulate(-1);
answer(C, X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
47 ms |
4508 KB |
Output is correct |
3 |
Correct |
49 ms |
4392 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1604 KB |
Output is correct |
6 |
Correct |
67 ms |
5632 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
47 ms |
4508 KB |
Output is correct |
3 |
Correct |
49 ms |
4392 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1604 KB |
Output is correct |
6 |
Correct |
67 ms |
5632 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
95 ms |
7200 KB |
Output is correct |
9 |
Correct |
107 ms |
7712 KB |
Output is correct |
10 |
Correct |
139 ms |
10124 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
47 ms |
4508 KB |
Output is correct |
3 |
Correct |
49 ms |
4392 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1604 KB |
Output is correct |
6 |
Correct |
67 ms |
5632 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
95 ms |
7200 KB |
Output is correct |
9 |
Correct |
107 ms |
7712 KB |
Output is correct |
10 |
Correct |
139 ms |
10124 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
131 ms |
9624 KB |
Output is correct |
15 |
Correct |
93 ms |
6596 KB |
Output is correct |
16 |
Correct |
146 ms |
10040 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
137 ms |
9844 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
78 ms |
5676 KB |
Output is correct |
3 |
Correct |
76 ms |
5688 KB |
Output is correct |
4 |
Correct |
126 ms |
8592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
78 ms |
5676 KB |
Output is correct |
3 |
Correct |
76 ms |
5688 KB |
Output is correct |
4 |
Correct |
126 ms |
8592 KB |
Output is correct |
5 |
Correct |
131 ms |
9960 KB |
Output is correct |
6 |
Correct |
124 ms |
9616 KB |
Output is correct |
7 |
Correct |
132 ms |
9728 KB |
Output is correct |
8 |
Correct |
124 ms |
9376 KB |
Output is correct |
9 |
Correct |
98 ms |
5656 KB |
Output is correct |
10 |
Correct |
121 ms |
9360 KB |
Output is correct |
11 |
Correct |
125 ms |
8984 KB |
Output is correct |
12 |
Correct |
78 ms |
5984 KB |
Output is correct |
13 |
Correct |
84 ms |
6276 KB |
Output is correct |
14 |
Correct |
86 ms |
6404 KB |
Output is correct |
15 |
Correct |
85 ms |
6580 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
77 ms |
5952 KB |
Output is correct |
18 |
Correct |
76 ms |
5948 KB |
Output is correct |
19 |
Correct |
77 ms |
5948 KB |
Output is correct |
20 |
Correct |
118 ms |
9184 KB |
Output is correct |
21 |
Correct |
125 ms |
8896 KB |
Output is correct |
22 |
Correct |
117 ms |
9012 KB |
Output is correct |