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>
#define pb push_back
#define fi first
#define se second
#define size(x) (int)(x.size())
using namespace std;
vector<vector<int>> adj;
vector<int> C, X, Y;
int cnt = -1;
void divide(vector<int> *a) {
if (size((*a)) == 2) {
X.pb((*a)[0]);
Y.pb((*a)[1]);
return;
}
vector<int> b, c;
for (int i = 0; i < size((*a)); i++) {
if (i & 1) c.pb( (*a)[i]);
else b.pb((*a)[i]);
}
X.pb(cnt); cnt--; Y.pb(0); int n = size(Y);
divide(&b);
Y[n - 1] = cnt; cnt--;
divide(&c);
}
void create_circuit(int M, vector<int> A) {
C.resize(M + 1);
int N = size(A);
int fact = 1, i = 0, last = 0;
vector<vector<int>> div;
div.push_back(A);
while (fact <= N) {
cnt--;
Y.push_back(last);
last = -size(Y);
if (N & (1 << i)) {
vector<vector<int>> newDiv;
vector<int> vec;
for (auto x : div) {
newDiv.push_back(vector<int>(x.begin(), x.begin() + size(x) / 2));
newDiv.push_back(vector<int>(x.begin() + size(x) / 2 + 1, x.end()));
vec.push_back(x[size(x) / 2]);
}
swap(div, newDiv);
if (i) {
X.push_back(cnt);
cnt--;
divide(&vec);
}
else X.push_back(vec[0]);
}
else {
X.push_back(0);
vector<vector<int>> newDiv;
for (auto x : div) {
newDiv.push_back(vector<int>(x.begin(), x.begin() + size(x) / 2));
newDiv.push_back(vector<int>(x.begin() + size(x) / 2, x.end()));
}
swap(div, newDiv);
}
fact <<= 1;
i++;
}
for (int i = 0; i <= M; i++) C[i] = last;
for (int& x: X) if (!x) x = last;
answer(C, X, Y);
}
# | 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... |