// AM+DG
/*
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
#define L(i, varmn, varmx) for(ll i = varmn; i < varmx; i++)
#define LR(i, varmx, varmn) for(ll i = varmx; i > varmn; i--)
#define LI(i, varmn, varmx) for(int i = varmn; i < varmx; i++)
#define LIR(i, varmx, varmn) for(int i = varmx; i > varmn; i--)
#define pb push_back
#include "doll.h"
struct pot_switch {
int id;
int x;
int y;
};
void construct_switches(int base_switch_num, const vi& to_connect, int p2, int offset, int size, vector<pot_switch>& switches_to_construct) {
if(size == 2) {
// Handle the special case here
switches_to_construct.pb({base_switch_num - offset, to_connect[p2 + offset - ((p2 << 1) - 1)], to_connect[(p2 << 1) + offset - ((p2 << 1) - 1)]});
} else if(size == 3) {
// Handle the special case here
switches_to_construct.pb({base_switch_num - offset, base_switch_num - (offset + p2), to_connect[(p2 << 1) + offset - ((p2 << 1) - 1)]});
// Recurse towards the first child
construct_switches(base_switch_num, to_connect, p2 << 1, offset + p2, size - (size >> 1), switches_to_construct);
} else {
// Recursive case
switches_to_construct.pb({base_switch_num - offset, base_switch_num - (offset + p2), base_switch_num - (offset + (p2 << 1))});
// Recurse left
construct_switches(base_switch_num, to_connect, p2 << 1, offset + p2, size - (size >> 1), switches_to_construct);
// Recurse right
construct_switches(base_switch_num, to_connect, p2 << 1, offset + (p2 << 1), (size >> 1), switches_to_construct);
}
}
int ceillog2(int n) {
int p2 = 1;
while(p2 < n) {
p2 <<= 1;
}
return p2;
}
void create_circuit(int m, std::vector<int> a) {
int n = a.size();
vi c(m + 1);
c[0] = -1;
for (int i = 1; i <= m; ++i) {
c[i] = 1;
}
// vi x(N), y(N);
// for (int k = 0; k < N; ++k) {
// x[k] = y[k] = a[k];
// }
vi x;
vi y;
vvi adjmat;
LI(i, 0, m + 1) {
vi adjmatr;
adjmat.pb(adjmatr);
}
LI(i, -1, n) {
if(i == -1) {
adjmat[0].pb(a[i + 1]);
} else if(i == n - 1) {
adjmat[a[i]].pb(0);
} else {
adjmat[a[i]].pb(a[i + 1]);
}
}
int last_switch = 0;
LI(i, 0, m + 1) {
int cur_num_next = adjmat[i].size();
if(cur_num_next == 0) {
c[i] = 0;
} else if(cur_num_next == 1) {
c[i] = adjmat[i][0];
} else {
/*
Construct switches needs...
whatever the last switch was,
the list of things it should connect the leaf node to
the current power of two separation (starts at 1 and doubles)
the current offset (starts at 0)
for the left tree, it increments by power * 1
for the right, its power * 2
Left tree must be of size ceil(N / 2)
right is size floor(N / 2)
*/
c[i] = last_switch - 1;
int actual_num_next = ceillog2(adjmat[i].size());
vi actual_next;
actual_next.reserve(actual_num_next);
LI(j, 0, actual_num_next - cur_num_next) {
actual_next.pb(last_switch - 1);
}
LI(j, 0, cur_num_next) {
actual_next.pb(adjmat[i][j]);
}
vector<pot_switch> switches_to_construct;
construct_switches(last_switch - 1, actual_next, 1, 0, actual_num_next, switches_to_construct);
sort(switches_to_construct.begin(), switches_to_construct.end(), [](pot_switch s1, pot_switch s2) {return s1.id > s2.id;}); // Sort by decreasing ID
LI(j, 0, actual_num_next - 1) {
x.pb(switches_to_construct[j].x);
y.pb(switches_to_construct[j].y);
}
last_switch -= actual_num_next - 1;
}
}
answer(c, x, y);
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
17 ms |
6960 KB |
Output is correct |
3 |
Correct |
14 ms |
6604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
4048 KB |
Output is correct |
6 |
Correct |
30 ms |
7884 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
17 ms |
6960 KB |
Output is correct |
3 |
Correct |
14 ms |
6604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
4048 KB |
Output is correct |
6 |
Correct |
30 ms |
7884 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
31 ms |
8396 KB |
Output is correct |
9 |
Correct |
30 ms |
8904 KB |
Output is correct |
10 |
Correct |
44 ms |
11468 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
17 ms |
6960 KB |
Output is correct |
3 |
Correct |
14 ms |
6604 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
4048 KB |
Output is correct |
6 |
Correct |
30 ms |
7884 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
31 ms |
8396 KB |
Output is correct |
9 |
Correct |
30 ms |
8904 KB |
Output is correct |
10 |
Correct |
44 ms |
11468 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
63 ms |
11744 KB |
Output is correct |
15 |
Correct |
30 ms |
7120 KB |
Output is correct |
16 |
Correct |
45 ms |
10192 KB |
Output is correct |
17 |
Correct |
0 ms |
436 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
50 ms |
12704 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
32 ms |
6388 KB |
Output is correct |
3 |
Partially correct |
56 ms |
10864 KB |
Output is partially correct |
4 |
Partially correct |
60 ms |
11752 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
32 ms |
6388 KB |
Output is correct |
3 |
Partially correct |
56 ms |
10864 KB |
Output is partially correct |
4 |
Partially correct |
60 ms |
11752 KB |
Output is partially correct |
5 |
Partially correct |
65 ms |
13472 KB |
Output is partially correct |
6 |
Partially correct |
68 ms |
14784 KB |
Output is partially correct |
7 |
Partially correct |
64 ms |
14528 KB |
Output is partially correct |
8 |
Partially correct |
74 ms |
14644 KB |
Output is partially correct |
9 |
Partially correct |
55 ms |
12648 KB |
Output is partially correct |
10 |
Partially correct |
81 ms |
14712 KB |
Output is partially correct |
11 |
Partially correct |
69 ms |
14776 KB |
Output is partially correct |
12 |
Partially correct |
43 ms |
9832 KB |
Output is partially correct |
13 |
Partially correct |
44 ms |
9548 KB |
Output is partially correct |
14 |
Partially correct |
43 ms |
9164 KB |
Output is partially correct |
15 |
Partially correct |
42 ms |
8900 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
604 KB |
Output is partially correct |
17 |
Partially correct |
34 ms |
8236 KB |
Output is partially correct |
18 |
Partially correct |
35 ms |
8136 KB |
Output is partially correct |
19 |
Partially correct |
40 ms |
8556 KB |
Output is partially correct |
20 |
Partially correct |
58 ms |
11200 KB |
Output is partially correct |
21 |
Partially correct |
60 ms |
12992 KB |
Output is partially correct |
22 |
Partially correct |
54 ms |
10684 KB |
Output is partially correct |