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"
#include <array>
#include <cmath>
using namespace std;
void create_circuit(int m, std::vector<int> a)
{
vector<int> c(m + 1, -1);
c[0] = a.front();
a.erase(a.begin());
a.push_back(0);
int n = a.size(), p = 1;
while (p < n) p *= 2;
int delta = p - n, ind = 0;
vector<array<int, 2>> adj{{0, 0}};
auto dfs = [&delta, &adj, &ind](auto self, int h) -> int
{
if (h == -1) return 0;
++ind;
int v = ind;
adj.push_back({0, 0});
if (delta & (1 << h))
{
delta ^= 1 << h;
adj[v][0] = -1;
}
else adj[v][0] = -self(self, h - 1);
adj[v][1] = -self(self, h - 1);
return v;
};
dfs(dfs, round(log2(p)) - 1);
vector<bool> state(adj.size());
for (int i : a)
{
auto dfs = [i, &adj, &state](auto self, int v) -> void
{
state[v] = !state[v];
if (adj[v][!state[v]] == 0)
{
adj[v][!state[v]] = i;
return;
}
self(self, -adj[v][!state[v]]);
};
dfs(dfs, 1);
}
vector<int> x((int)adj.size() - 1), y((int)adj.size() - 1);
for (int i = 1; i < adj.size(); ++i)
{
x[i - 1] = adj[i][0];
y[i - 1] = adj[i][1];
}
answer(c, x, y);
}
Compilation message (stderr)
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i = 1; i < adj.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... |