#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
void create_circuit(int M, vector<int> A) {
int N = A.size();
int source = -1;
vector<int> C(M + 1);
for(int &x: C) x = source;
int sz = 0;
while((1<<sz) <= N) sz++;
vector<int> X(N+sz), Y(N+sz);
auto buildtree = [&](int len, int shift){
vector<pair<int,int>> res(len-1);
for(int i=0; i<len/2-1; i++) res[i] = {shift - (2*i+1), shift - (2*i+2)};
for(int i=len/2-1; i<len-1; i++) res[i] = {M+1, M+1};
return res;
};
int curr = -sz-1;
for(int i=0; i<sz; i++){
Y[i] = -i-2;
if((N & (1 << (sz-i-1))) == 0) X[i] = source;
else{
if(sz-i-1 == 0){
X[i] = M+1;
}
else{
X[i] = curr;
auto tree = buildtree((1<<(sz-i-1)), curr);
for(auto [a, b]: tree) X[-curr-1] = a, Y[-curr-1] = b, curr--;
}
}
}
Y[sz-1] = 0;
vector<int> state(N+sz);
function<void(int, int)> findnext = [&](int v, int id){
int u = -v-1;
assert(v < 0);
int next = state[u]?Y[u]:X[u];
if(next == M+1){
if(state[u]) Y[u] = id;
else X[u] = id;
state[u] ^= 1;
return;
}
state[u] ^= 1;
findnext(next, id);
};
for(int i=0; i<N; i++){
findnext(source, A[i]);
}
X.resize(-curr-1);
Y.resize(-curr-1);
//assert(accumulate(state.begin(), state.end(), 0) == 0);
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
360 KB |
Output is correct |
2 |
Correct |
34 ms |
4364 KB |
Output is correct |
3 |
Correct |
32 ms |
3736 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Correct |
49 ms |
5788 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
360 KB |
Output is correct |
2 |
Correct |
34 ms |
4364 KB |
Output is correct |
3 |
Correct |
32 ms |
3736 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Correct |
49 ms |
5788 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
62 ms |
6732 KB |
Output is correct |
9 |
Correct |
68 ms |
7096 KB |
Output is correct |
10 |
Correct |
95 ms |
10124 KB |
Output is correct |
11 |
Correct |
0 ms |
344 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 |
360 KB |
Output is correct |
2 |
Correct |
34 ms |
4364 KB |
Output is correct |
3 |
Correct |
32 ms |
3736 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Correct |
49 ms |
5788 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
62 ms |
6732 KB |
Output is correct |
9 |
Correct |
68 ms |
7096 KB |
Output is correct |
10 |
Correct |
95 ms |
10124 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
94 ms |
9876 KB |
Output is correct |
15 |
Correct |
61 ms |
6476 KB |
Output is correct |
16 |
Correct |
101 ms |
9596 KB |
Output is correct |
17 |
Correct |
0 ms |
356 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
95 ms |
10104 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
58 ms |
5056 KB |
Output is correct |
3 |
Correct |
57 ms |
4808 KB |
Output is correct |
4 |
Correct |
86 ms |
7240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
58 ms |
5056 KB |
Output is correct |
3 |
Correct |
57 ms |
4808 KB |
Output is correct |
4 |
Correct |
86 ms |
7240 KB |
Output is correct |
5 |
Correct |
90 ms |
8132 KB |
Output is correct |
6 |
Correct |
91 ms |
7964 KB |
Output is correct |
7 |
Correct |
92 ms |
8072 KB |
Output is correct |
8 |
Correct |
89 ms |
7700 KB |
Output is correct |
9 |
Correct |
57 ms |
4808 KB |
Output is correct |
10 |
Correct |
96 ms |
7728 KB |
Output is correct |
11 |
Correct |
89 ms |
7244 KB |
Output is correct |
12 |
Correct |
57 ms |
4936 KB |
Output is correct |
13 |
Correct |
59 ms |
5200 KB |
Output is correct |
14 |
Correct |
59 ms |
5372 KB |
Output is correct |
15 |
Correct |
59 ms |
5440 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
55 ms |
4812 KB |
Output is correct |
18 |
Correct |
62 ms |
5060 KB |
Output is correct |
19 |
Correct |
58 ms |
5048 KB |
Output is correct |
20 |
Correct |
90 ms |
7436 KB |
Output is correct |
21 |
Correct |
98 ms |
7416 KB |
Output is correct |
22 |
Correct |
87 ms |
7240 KB |
Output is correct |