이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
vector<int> C, X, Y;
struct node
{
unordered_set<int> options;
vector<int> folowing;
int visited = 0;
};
vector<node> g;
void rec(int index, int value, vector<bool> &tree, vector<int> &X, vector<int> &Y)
{
if (index > (tree.size() - 1) / 2)
{
if (tree[index])
X[index - 1] = value;
else
Y[index - 1] = value;
}
else if (tree[index])
rec(index * 2, value, tree, X, Y);
else
rec(index * 2 + 1, value, tree, X, Y);
tree[index] = !tree[index];
}
pair<vector<int>, vector<int>> maketree(int offset, vector<int> const &folows)
{
int ends = 2;
while (ends < (int)folows.size())
ends *= 2;
vector<int> X(ends - 1), Y(ends - 1);
vector<bool> tree(ends, true);
for (int i = 1; i < ends / 2; i++)
{
X[i - 1] = i * -2 + offset;
Y[i - 1] = i * -2 - 1 + offset;
}
while (ends-- != (int)folows.size()) // lose ends
rec(1, -1, tree, X, Y);
for (int i : folows)
rec(1, i, tree, X, Y);
return {X, Y};
}
void create_circuit(int M, std::vector<int> A)
{
int N = A.size();
g.resize(M + 1);
C.resize(M + 1, 0);
g[0].folowing.push_back(A[0]);
g[0].options.insert(A[0]);
for (int i = 1; i < N; i++)
{
g[A[i - 1]].folowing.push_back(A[i]);
g[A[i - 1]].options.insert(A[i]);
}
g[A[N - 1]].folowing.push_back(0);
g[A[N - 1]].options.insert(0);
for (int i = 0; i < M + 1; i++)
{
if ((int)g[i].options.size() == 1)
C[i] = g[i].folowing[0];
else if (g[i].options.size() == 0)
C[i] = 0;
else
{
C[i] = -X.size() - 1;
auto tmp = maketree((int)X.size(), g[i].folowing);
X.insert(X.end(), tmp.first.begin(), tmp.first.end());
Y.insert(Y.end(), tmp.second.begin(), tmp.second.end());
}
}
answer(C, X, Y);
}
컴파일 시 표준 에러 (stderr) 메시지
doll.cpp: In function 'void rec(int, int, std::vector<bool>&, std::vector<int>&, std::vector<int>&)':
doll.cpp:20:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if (index > (tree.size() - 1) / 2)
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |