#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
int counter = 0;
struct Node {
array<Node*, 2> c = {nullptr, nullptr};
int to = 0, idx = -1;
bool terminal() {
return c[0] == nullptr && c[1] == nullptr;
}
};
Node* construct(int sz, int depth) {
if(sz <= 0) return nullptr;
Node* root = new Node();
if(depth <= 0) return root;
root->idx = ++counter;
int sz_l = 1<<(31-__builtin_clz(sz));
if(sz_l == sz && sz > 1) sz_l /= 2;
root->c[0] = construct(sz-sz_l, depth-1);
root->c[1] = construct(sz_l, depth-1);
for(auto n : root->c) {
if(n == nullptr) continue;
}
return root;
}
// first time going to terminal node
void walk(Node* curr, Node* root, int target, vector<int> &X, vector<int> &Y) {
Node* to = curr->c[curr->to];
if(!to) {
if(curr->to) Y[curr->idx-1] = -root->idx;
else X[curr->idx-1] = -root->idx;
curr->to ^= 1;
walk(root, root, target, X, Y);
}
else if(to->terminal()) {
if(curr->to) Y[curr->idx-1] = target;
else X[curr->idx-1] = target;
curr->to ^= 1;
}
else {
if(curr->to) Y[curr->idx-1] = -to->idx;
else X[curr->idx-1] = -to->idx;
curr->to ^= 1;
walk(to, root, target, X, Y);
}
}
void create_circuit(int M, vector<int> A) {
int N = A.size();
int depth = 31-__builtin_clz(N-1)+1;
Node* root = construct(N, depth);
vector<int> C(M+1);
vector<int> X(counter, -10000), Y(counter, -10000);
C[0] = A[0];
for(int i = 1; i <= M; i++) C[i] = -1;
for(int i = 1; i < N; i++) {
walk(root, root, A[i], X, Y);
}
walk(root, root, 0, X, Y);
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
37 ms |
7984 KB |
Output is correct |
3 |
Correct |
37 ms |
7680 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
1364 KB |
Output is correct |
6 |
Incorrect |
60 ms |
11912 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
37 ms |
7984 KB |
Output is correct |
3 |
Correct |
37 ms |
7680 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
1364 KB |
Output is correct |
6 |
Incorrect |
60 ms |
11912 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
37 ms |
7984 KB |
Output is correct |
3 |
Correct |
37 ms |
7680 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
1364 KB |
Output is correct |
6 |
Incorrect |
60 ms |
11912 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
73 ms |
13536 KB |
Output is correct |
3 |
Correct |
70 ms |
13472 KB |
Output is correct |
4 |
Partially correct |
164 ms |
21300 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
73 ms |
13536 KB |
Output is correct |
3 |
Correct |
70 ms |
13472 KB |
Output is correct |
4 |
Partially correct |
164 ms |
21300 KB |
Output is partially correct |
5 |
Partially correct |
139 ms |
21708 KB |
Output is partially correct |
6 |
Partially correct |
154 ms |
21508 KB |
Output is partially correct |
7 |
Partially correct |
168 ms |
21580 KB |
Output is partially correct |
8 |
Partially correct |
131 ms |
21420 KB |
Output is partially correct |
9 |
Partially correct |
67 ms |
13504 KB |
Output is partially correct |
10 |
Partially correct |
162 ms |
21320 KB |
Output is partially correct |
11 |
Partially correct |
141 ms |
21164 KB |
Output is partially correct |
12 |
Correct |
72 ms |
13540 KB |
Output is correct |
13 |
Correct |
67 ms |
13724 KB |
Output is correct |
14 |
Correct |
70 ms |
13748 KB |
Output is correct |
15 |
Correct |
68 ms |
13768 KB |
Output is correct |
16 |
Correct |
2 ms |
724 KB |
Output is correct |
17 |
Correct |
65 ms |
13544 KB |
Output is correct |
18 |
Correct |
95 ms |
13516 KB |
Output is correct |
19 |
Correct |
69 ms |
13552 KB |
Output is correct |
20 |
Partially correct |
127 ms |
21344 KB |
Output is partially correct |
21 |
Partially correct |
153 ms |
21300 KB |
Output is partially correct |
22 |
Partially correct |
133 ms |
21324 KB |
Output is partially correct |