이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |