# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
290968 | Tc14 | 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.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
//#include "task1.h"
using namespace std;
#define ve vector
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 10;
void create_circuit(int m, ve<int> A) {
int n, l, s, k, z;
ve<int> C, X, Y;
ve<bool> B;
n = A.size();
l = max((int)ceil(log2(n)), 1);
s = 1 << l;
/*
cout << n << endl;
*/
C = ve<int>(m + 1);
X = ve<int>(s - 1);
Y = ve<int>(s - 1);
B = ve<bool>(s);
for (int i = 0; i <= m; i++) C[i] = -1;
for (int i = 1; i < s / 2; i++) {
X[i - 1] = -(2 * i);
Y[i - 1] = -(2 * i + 1);
}
for (int i = 0; i < s; i++) {
k = 1;
for (int j = 0; j < l - 1; j++) {
if (B[k]) {
B[k] = !B[k];
k = -Y[k - 1];
}
else {
B[k] = !B[k];
k = -X[k - 1];
}
}
if (i < n) z = i + 1;
else z = -1;
if (B[k]) {
B[k] = !B[k];
Y[k - 1] = z;
}
else {
B[k] = !B[k];
X[k - 1] = z;
}
}
/*
for (int i = 0; i < s - 1; i++) {
cout << X[i] << " " << Y[i] << endl;
}
*/
answer(C, X, Y);
}