#include "doll.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int S, mp[400005];
vector<int> X, Y;
int ID = 0;
void dfs(int l, int r, int v = 0, int depth = 0) {
++ID;
if (l + 1 == r) {
if (l < S) X.push_back(-1);
else X.push_back(v);
Y.push_back(v | (1 << depth));
return;
}
int cur_vtx = ID - 1;
int m = (l + r) / 2;
Y.push_back(69);
if (m < S) {
X.push_back(-1);
}
else {
X.push_back(-ID - 1);
dfs(l, m, v, depth + 1);
}
Y[cur_vtx] = -ID - 1;
dfs(m + 1, r, v | (1 << depth), depth + 1);
}
void create_circuit(int M, vector<int> A) {
if (A.size() == 1) {
vector<int> C = { A[0], 0 }, X(0), Y(0);
answer(C, X, Y);
return;
}
vector<int> C;
C.push_back(A[0]);
A.erase(A.begin());
A.push_back(0);
for (int i = 0; i < M; ++i) C.push_back(-1);
int K = ceil(log2(A.size()));
S = (1 << K) - A.size();
dfs(0, (1 << K) - 1);
for (int i = 0; i < ID; i++) {
if (X[i] >= 0) mp[X[i]] = 1;
if (Y[i] >= 0) mp[Y[i]] = 1;
}
int iA = 0;
for (int i = 0; i < (1 << K); ++i) {
if (mp[i]) {
mp[i] = A[iA];
++iA;
}
}
for (int i = 0; i < ID; i++) {
if (X[i] >= 0) X[i] = mp[X[i]];
if (Y[i] >= 0) Y[i] = mp[Y[i]];
}
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
39 ms |
3896 KB |
Output is correct |
3 |
Correct |
37 ms |
4288 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
13 ms |
1604 KB |
Output is correct |
6 |
Correct |
47 ms |
5488 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
39 ms |
3896 KB |
Output is correct |
3 |
Correct |
37 ms |
4288 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
13 ms |
1604 KB |
Output is correct |
6 |
Correct |
47 ms |
5488 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
56 ms |
5728 KB |
Output is correct |
9 |
Correct |
62 ms |
7656 KB |
Output is correct |
10 |
Correct |
85 ms |
8896 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
39 ms |
3896 KB |
Output is correct |
3 |
Correct |
37 ms |
4288 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
13 ms |
1604 KB |
Output is correct |
6 |
Correct |
47 ms |
5488 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
56 ms |
5728 KB |
Output is correct |
9 |
Correct |
62 ms |
7656 KB |
Output is correct |
10 |
Correct |
85 ms |
8896 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 |
87 ms |
8536 KB |
Output is correct |
15 |
Correct |
54 ms |
6860 KB |
Output is correct |
16 |
Correct |
78 ms |
8444 KB |
Output is correct |
17 |
Correct |
2 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
118 ms |
8760 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
46 ms |
4968 KB |
Output is correct |
3 |
Correct |
49 ms |
6016 KB |
Output is correct |
4 |
Correct |
72 ms |
7736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
46 ms |
4968 KB |
Output is correct |
3 |
Correct |
49 ms |
6016 KB |
Output is correct |
4 |
Correct |
72 ms |
7736 KB |
Output is correct |
5 |
Correct |
92 ms |
8224 KB |
Output is correct |
6 |
Correct |
92 ms |
7976 KB |
Output is correct |
7 |
Correct |
88 ms |
8156 KB |
Output is correct |
8 |
Correct |
74 ms |
8004 KB |
Output is correct |
9 |
Correct |
47 ms |
6120 KB |
Output is correct |
10 |
Correct |
74 ms |
7908 KB |
Output is correct |
11 |
Correct |
76 ms |
7624 KB |
Output is correct |
12 |
Correct |
52 ms |
6340 KB |
Output is correct |
13 |
Correct |
64 ms |
5388 KB |
Output is correct |
14 |
Correct |
54 ms |
6728 KB |
Output is correct |
15 |
Correct |
53 ms |
6788 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
65 ms |
5008 KB |
Output is correct |
18 |
Correct |
71 ms |
4960 KB |
Output is correct |
19 |
Correct |
56 ms |
6336 KB |
Output is correct |
20 |
Correct |
74 ms |
7776 KB |
Output is correct |
21 |
Correct |
73 ms |
7660 KB |
Output is correct |
22 |
Correct |
75 ms |
7680 KB |
Output is correct |