This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "doll.h"
// N + 1 = 15
// num_bits = 4
// we should have: 1 + 2 + 4 + 8
void create_circuit(int M, std::vector<int> A) {
int N = A.size();
std::vector<int> C(M + 1);
for (int i = 0; i <= M; ++i) {
C[i] = -1;
}
std::vector<int> X, Y;
int num_bits = 0;
int tmp = N + 1;
while (tmp > 0) {
++num_bits;
tmp >>= 1;
}
for (int k = 1; k < num_bits; ++k) {
int n_nodes = 1 << (k-1);
for (int n = 0; n < n_nodes; n++) {
X.push_back(-n * 2);
Y.push_back(-(n * 2 + 1));
}
}
// N nodes of the last level are connected to the triggers, the last one
// 2^bits-N-1 to -1
// and the last one to origin
int n_leaves = 1 << (num_bits-1);
int idx_b = X.size();
for (int n = 0; n < n_leaves; n++) {
X.push_back(-1);
Y.push_back(-1);
}
for (int n = 0; n < N; n++) {
// revert the number
int n_inv = 0;
int n_tmp = n;
for (int l=0; l<num_bits; l++) {
n_inv = (n_inv << 1) | (n_tmp & 1);
n_tmp >>= 1;
}
if (n_inv & 1) {
Y[idx_b + n_inv/2] = A[n];
}
else {
X[idx_b + n_inv/2] = A[n];
}
}
Y[idx_b + n_leaves - 1] = 0;
answer(C, X, Y);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |