이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
struct node
{
vector<int> follow;
set<int> options;
};
vector<node> g;
vector<int> C, X, Y;
int mx = 2;
vector<bool> tree((1 << 18) + 5, true);
void rec(int index, int value)
{
if (index >= mx / 2)
{
if (tree[index])
X[index - 1] = value;
else
Y[index - 1] = value;
}
else if (tree[index])
rec(index * 2, value);
else
rec(index * 2 + 1, value);
tree[index] = !tree[index];
}
void create_circuit(int M, std::vector<int> A)
{
int N = A.size();
A.push_back(0);
while (N >= (mx = mx * 2) * 2)
;
{ // built graph
g.resize(M + 1);
g[0].follow.push_back(A[0]);
g[0].options.insert(A[0]);
for (int i = 1; i < N; i++)
{
g[A[i - 1]].follow.push_back(A[i]);
g[A[i - 1]].options.insert(A[i]);
}
}
C.resize(M + 1);
fill(C.begin(), C.end(), -1);
// eliminate unnecessary
int toeliminate = N - mx;
toeliminate += 2;
for (int i = 0; i < M + 1; i++)
{
if (g[i].options.size() == 1 && toeliminate > 0)
{
toeliminate -= g[i].follow.size();
C[i] = g[i].follow.back();
}
else if (g[i].options.empty())
C[i] = 0;
}
if (toeliminate > 0)
{
for (int i = 0; i < M + 1; i++)
{
if (g[i].follow.size() == 2)
{
toeliminate -= 2;
X.push_back(g[i].follow[0]);
Y.push_back(g[i].follow[1]);
C[i] = -X.size();
}
else if (g[i].options.size() == 2 && g[i].follow.size() % 2 == 2)
{
bool b = true;
for (int e = 0; e < g[i].follow.size(); e++)
b &= (g[i].follow[e] == g[i].follow[e % 2]);
if (b)
{
toeliminate -= 2;
X.push_back(g[i].follow[0]);
Y.push_back(g[i].follow[1]);
C[i] = -X.size();
}
}
if (toeliminate <= 0)
break;
}
}
int offset = X.size() + 1;
for (int i = 0; i < mx - 1; i++)
{
X.push_back(-offset);
Y.push_back(-offset);
}
for (int i = 1; i < mx / 2; i++)
{
X[i - 1] = i * -2 - offset;
Y[i - 1] = i * -2 - 1 - offset;
}
bool b = false;
int last = -1;
for (int i = 1; i < N + 1; i++)
{
if (!b && C[A[i - 1]] == -1)
{
last = A[i];
b = true;
}
else if (C[A[i - 1]] == -1)
{
rec(1, last);
last = A[i];
}
}
Y[Y.size() - 1] = last;
if (b)
answer(C, X, Y);
else
answer(C, {}, {});
}
컴파일 시 표준 에러 (stderr) 메시지
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:87:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for (int e = 0; e < g[i].follow.size(); e++)
| ~~^~~~~~~~~~~~~~~~~~~~
# | 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... |