# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
286179 | ne4eHbKa | 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 "doll.h"
#include <bits/stdc++.h>
using namespace std;
namespace solution {
typedef vector<int> vi;
map<int, list<int> > f;
vi c, x, y;
int s;
int swicch(list<int> &t) {
int i = s++;
x.push_back(0);
y.push_back(0);
list<int> a, b;
int cnt = 0;
for(int &j : t)
(cnt++ & 1 ? b : a).push_back(j);
x[i] = a.size() - 1 ? swicch(a) : a.front();
y[i] = b.size() - 1 ? swicch(b) : b.front();
return -(i + 1);
}
void trigger(int i) {
if(f.find(i) == f.end()) {
c[i] = 0;
return;
}
list<int> &t = f[i];
if(t.size() == 1) {
c[i] = t.front();
return;
}
c[i] = swicch(t);
}
}
void create_circuit (int m, ints a) {
using namespace solution;
int n = a.size();
f.clear();
for(int i = 1; i < n; ++i)
f[a[i - 1]].push_back(a[i]);
f[a.back()].push_back(0);
c.resize(m + 1);
x.clear();
y.clear();
s = 0;
c[0] = a.front();
for(int i = 1; i <= m; ++i)
trigger(i);
answer(c, x, y);
}