이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
#define sz(x) (int)x.size()
int S, N;
vector<int> X, Y;
vector<int> C;
void build(int leaves_start, int node = 1)
{
if (node == 1)
{
X.resize(leaves_start - 1, -1), Y.resize(leaves_start - 1, -1);
C[0] = -1;
}
if (2 * node < leaves_start)
{
X[node - 1] = -2 * node;
build(leaves_start, 2 * node);
}
if (2 * node + 1 < leaves_start)
{
Y[node - 1] = -2 * node - 1;
build(leaves_start, 2 * node + 1);
}
}
void create_circuit(int M, vector<int> A)
{
N = A.size();
C.resize(M + 1);
int binLog = -1;
for (int i = 0; i < 20; i++)
if ((1 << i) >= N)
{
binLog = i;
break;
}
int pow2 = 1 << binLog;
build(pow2);
int start_leaf = 2 * pow2 - N;
for (int i = 0; i < N; i++)
{
C[A[i]] = -1;
if (i == N - 1)
C[A[i]] = 0;
int mask = i + (pow2 - N);
int dest_node = 0;
for (int j = 0; j < binLog; j++)
if ((mask >> j) & 1)
dest_node += 1 << (binLog - j - 1);
dest_node += (1 << binLog);
int parent = (dest_node) / 2;
if (2 * parent == dest_node)
{
X[parent - 1] = A[i];
}
else
{
Y[parent - 1] = A[i];
}
}
// cout << pow2 << '\n';
// for (auto x : C)
// cout << x << " ";
// cout << '\n';
// for (auto x : X)
// cout << x << " ";
// cout << '\n';
// for (auto x : Y)
// cout << x << " ";
// cout << '\n';
answer(C, X, Y);
}
컴파일 시 표준 에러 (stderr) 메시지
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:46:9: warning: unused variable 'start_leaf' [-Wunused-variable]
46 | int start_leaf = 2 * pow2 - N;
| ^~~~~~~~~~
# | 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... |