# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
230637 | DrSwad | Mechanical Doll (IOI18_doll) | C++17 | 0 ms | 0 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 <bits/stdc++.h>
using namespace std;
const int N = int(4e5) + 10;
int c[N];
int x[N], y[N];
int switches_used;
void handle(int from, int L, int R, vector<int> &a) {
if (R - L + 1 <= 0) return;
if (R - L + 1 == 1) {
c[from] = a[0];
return;
}
int at_switch = ++switches_used;
if (R - L + 1 == a.size()) c[from] = -at_switch;
int mid = (L + R) >> 1;
if (mid - L + 1 == 1) x[at_switch] = a[L];
else {
x[at_switch] = -(switches_used + 1);
handle(from, L, mid, a);
}
if (R - mid == 1) y[at_switch] = a[R];
else {
y[at_switch] = -(switches_used + 1);
handle(from, mid + 1, R, a);
}
}
void create_circuit(int m, vector<int> a) {
a.push_back(0);
c[0] = a[0];
int n = a.size();
vector<vector<int>> v(m + 1);
for (int i = 0; i < n - 1; i++) v[a[i]].push_back(a[i + 1]);
for (int i = 1; i <= m; i++) handle(i, 0, (int)v[i].size() - 1, v[i]);
answer(vector<int>(c + 0, c + m + 1), vector<int>(x + 1, x + switches_used + 1), vector<int>(y + 1, y + switches_used + 1));
}