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;
vector<int> C, X(15), Y(15);
vector<bool> tree(16);
void rec(int index, int value)
{
if (index > 7)
{
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();
fill(tree.begin(), tree.end(), true);
C.resize(M + 1);
if (N == 16)
{
for (int i = 1; i < 8; i++)
{
X[i - 1] = i * -2;
Y[i - 1] = i * -2 - 1;
}
for (int i = 1; i < N; i++)
rec(1, A[i]);
rec(1, 0);
fill(C.begin(), C.end(), -1);
C[0] = A[0];
}
else if (M == 1)
{
C[0] = 1;
C[1] = -1;
X.resize(18);
Y.resize(X.size());
iota(Y.rbegin(), Y.rend(), -(Y.size() + 1));
Y[Y.size() - 1] = 0;
int t = 1 << X.size();
for (int i = 1; i <= X.size(); i++)
{
if (t - (1 << (X.size() - i)) >= N)
{
t -= (1 << (X.size() - i));
X[i - 1] = -1;
}
else
X[i - 1] = 1;
}
}
else
{
vector<vector<int>> g(M + 1);
X = Y = {};
fill(C.begin(), C.end(), 0);
C[0] = A[0];
g[0].push_back(A[0]);
for (int i = 1; i < N; i++)
g[A[i - 1]].push_back(A[i]);
g[A[N - 1]].push_back(0);
for (int i = 0; i < M + 1; i++)
{
if (g[i].size() == 0)
C[i] = 0;
else if (g[i].size() == 1)
C[i] = g[i][0];
else if (g[i].size() == 2)
{
X.push_back(g[i][0]);
Y.push_back(g[i][1]);
C[i] = X.size() * -1;
}
}
}
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 1; i <= X.size(); i++)
| ~~^~~~~~~~~~~
# | 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... |