| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 756717 | boris_mihov | Mechanical Doll (IOI18_doll) | C++17 | 719 ms | 13352 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 <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>
#include "doll.h"
typedef long long llong;
const int MAXN = 1000000 + 10;
const int MAXS = 1000000 + 10;
const int INF = 1e9;
int n, m, cnt;
std::vector <int> a, x, y, c;
int perm[MAXN];
int treeRoot;
void rec(int l, int r, int root)
{
assert(l != r);
if (l + 1 == r)
{
if (perm[l] < a.size()) y[root - 1] = a[perm[l]];
else y[root - 1] = -treeRoot;
if (perm[r] < a.size()) x[root - 1] = a[perm[r]];
else x[root - 1] = -treeRoot;
return;
}
int mid = (l + r) / 2;
x.push_back(0);
x.push_back(0);
y.push_back(0);
y.push_back(0);
cnt += 2;
y[root - 1] = -(cnt - 1);
x[root - 1] = -cnt;
rec(l, mid, -y[root - 1]);
rec(mid + 1, r, -x[root - 1]);
}
int reversed(int x, int bits)
{
int res = 0;
for (int i = 0 ; i < bits ; ++i)
{
if (x & (1 << i))
{
res |= (1 << bits - 1 - i);
}
}
return res;
}
void create_circuit(int M, std::vector <int> A)
{
m = M; n = A.size(); A.push_back(0); a = A;
c.resize(m + 1);
if (a.size() == 1)
{
c[a[0]] = 0;
} else
{
for (int i = 0 ; i <= m ; ++i)
{
c[i] = -1;
}
int sz = 1, bits = 0;
while (sz < a.size())
{
sz <<= 1;
bits++;
}
x.push_back(0);
y.push_back(0);
std::reverse(a.begin(), a.end());
std::iota(perm, perm + sz, 0);
std::sort(perm, perm + sz, [&](int x, int y)
{
return reversed(x, bits) < reversed(y, bits);
});
cnt++;
treeRoot = cnt;
rec(0, sz - 1, 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... | ||||
