# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
755548 | boris_mihov | Mechanical Doll (IOI18_doll) | C++17 | 74 ms | 12480 KiB |
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 <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
typedef long long llong;
const int MAXN = 100000 + 10;
const int MAXS = 400000 + 10;
const int INF = 1e9;
int n, m, cnt;
std::vector <int> x, y, c;
std::vector <int> g[MAXN];
void rec(int l, int r, int node, int root)
{
if (r - l + 1 == 2)
{
x[root - 1] = g[node][l];
y[root - 1] = g[node][r];
return;
}
if (__builtin_popcount(r - l + 1) == 2 && ((r - l + 1) & 1))
{
x.push_back(0);
y.push_back(0);
x[root - 1] = -(++cnt);
y[root - 1] = g[node][r];
rec(l, r - 1, node, cnt);
return;
}
if (__builtin_popcount(r - l + 1) == 1)
{
x.push_back(0);
y.push_back(0);
x.push_back(0);
y.push_back(0);
x[root - 1] = cnt - 1;
y[root - 1] = cnt;
int mid = (l + r) / 2;
rec(l, mid, node, cnt - 1);
rec(mid + 1, r, node, cnt);
return;
}
int clz = __builtin_clz(r - l + 1);
assert((r - l + 1) & (1 << 32 - clz));
x.push_back(0);
y.push_back(0);
x.push_back(0);
y.push_back(0);
x[root - 1] = cnt - 1;
y[root - 1] = cnt;
rec(l, l + (1 << 32 - clz) - 1, node, cnt - 1);
rec(l + (1 << 32 - clz), r, node, cnt);
}
void create_circuit(int M, std::vector <int> A)
{
m = M; n = A.size();
for (int i = 1 ; i <= n ; ++i)
{
g[A[i - 1]].push_back(A[i]);
}
c.resize(m + 1); c[0] = A[0];
g[A[n]].push_back(0);
for (int i = 1 ; i <= m ; ++i)
{
if (g[i].empty())
{
continue;
}
if (g[i].size() == 1)
{
c[i] = g[i][0];
} else
{
c[i] = -(++cnt);
x.push_back(0);
y.push_back(0);
rec(0, g[i].size() - 1, i, cnt);
}
}
answer(c, x, y);
}
Compilation message (stderr)
# | 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... |