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
using namespace std;
vector<vector<int>> adj;
vector<int> C, X, Y;
int cnt = -1;
void divide(vector<int> *a, int prev) {
if (a->size() == 2) {
X.pb((*a)[0]);
Y.pb((*a)[1]);
return;
}
vector<int> b, c;
for (int i = 0; i < a->size(); i++) {
if (i & 1) c.pb( (*a)[i]);
else b.pb((*a)[i]);
}
if (b.size() > c.size()) {
c.pb(b.back());
b.back() = prev;
}
X.pb(cnt); cnt--; Y.pb(0); int n = Y.size();
divide(&b, cnt + 1);
Y[n - 1] = cnt; cnt--;
divide(&c, cnt + 1);
}
void build(int x) {
int n = adj[x].size();
if (!n) adj[x].pb(0);
if (n == 1) C[x] = adj[x][0];
else if (n) {
C[x] = cnt; cnt--;
divide(&adj[x], cnt + 1);
}
}
void create_circuit(int M, vector<int> A) {
/*if (M == 1) {
int N = A.size();
A.push_back(0);
vector<int> C(M + 1, INT_MAX), X, Y;
C[0] = A[0];
int time = N - 1;
vector<pair<int,int>> fact = {{1, 1}};
int cnt = -1;
while (time) {
int next = 0;
for (auto x : fact) {
if (time % x.first == 0) {
time -= x.first;
next = x.first;
X.push_back(x.second);
if (cnt != -1) Y.push_back(cnt);
else C[1] = cnt;
cnt--;
break;
}
}
for (auto &x : fact) x.first += next;
fact.push_back({next, cnt + 1});
}
if (cnt != -1) Y.push_back(0);
else C[1] = 0;
answer(C, X, Y);
return;
}*/
int N = A.size();
A.push_back(0);
C.resize(M + 1);
adj.resize(M + 1);
adj[0].pb(A[0]); C[0] = A[0];
for (int i = 1; i <= N; i++) adj[A[i-1]].pb(A[i]);
for (int i = 1; i <= M; i++) build(i);
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'void divide(std::vector<int>*, int)':
doll.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < a->size(); i++) {
| ~~^~~~~~~~~~~
# | 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... |