This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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();
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]);
}
g[A[N - 1]].follow.push_back(0);
g[A[N - 1]].options.insert(0);
}
int toeliminate = N - mx;
toeliminate++;
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 && g[i].follow.back() != 0)
{
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;
}
for (int i = 1; i < N; i++)
{
if (C[A[i - 1]] == -1)
rec(1, A[i]);
}
Y[Y.size() - 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... |