이 제출은 이전 버전의 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)
{
assert(false);
A.push_back(0);
int N = A.size();
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]);
}
}
int toeliminate = N - mx;
toeliminate += 2;
C.resize(M + 1);
fill(C.begin(), C.end(), -1);
// eliminate unnecessary
for (int i = 0; i < M + 1; i++)
{
if (g[i].options.size() == 1)
{
toeliminate -= g[i].follow.size();
C[i] = g[i].follow.back();
}
else if (g[i].options.empty())
C[i] = 0;
}
assert(toeliminate <= 0);
X.resize(mx - 1, -1);
Y.resize(mx - 1, -1);
for (int i = 1; i < mx / 2; i++)
{
X[i - 1] = i * -2;
Y[i - 1] = i * -2 - 1;
}
bool b = false;
int last = 0;
for (int i = 1; i < N; 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, {}, {});
}
# | 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... |