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;
#define sz(x) ((int)x.size())
void answer(vector<int> C, vector<int> X, vector<int> Y);
int n, m;
vector<int> a;
vector<vector<int>> adj;
int p = 0;
vector<int> c, x, y;
int new_switch(int g, int d) {
p++;
x.push_back(g);
y.push_back(d);
return -p;
}
int new_switch(int g) {
p++;
x.push_back(-p);
y.push_back(g);
return -p;
}
vector<int> liste;
int PR = 1;
int mom = -1;
int build(int X, int pr) {
if(pr == 1) {
mom = new_switch(0, 0);
int g = build(X, 2 * pr);
int d = build(X + pr, 2 * pr);
x[-mom-1] = g;
y[-mom-1] = d;
return mom;
}
if(pr == PR) return (liste[X] == -1 ? mom : liste[X]);
int g = build(X, 2 * pr);
int d = build(X + pr, 2 * pr);
return new_switch(g, d);
}
int create(int t) {
if(sz(adj[t]) == 0) return 0;
if(sz(adj[t]) == 1) return adj[t][0];
int pr = 1;
while(pr < sz(adj[t])) pr *= 2;
PR = pr;
liste.assign(pr, -1);
for(int i = 0; i < pr - sz(adj[t]); ++i)
liste[i] = -1;
for(int i = pr - sz(adj[t]); i < pr; ++i)
liste[i] = adj[t][i - pr + sz(adj[t])];
return build(0, 1);
}
void create_circuit(int M, vector<int> A) {
n = (int)A.size();
m = M;
a = A;
c.assign(m + 1, 0);
adj.assign(m + 1, vector<int>());
for(int i = 0; i < n - 1; ++i)
adj[a[i]].push_back(a[i + 1]);
adj[0].push_back(a[0]);
adj[a.back()].push_back(0);
for(int i = 0; i <= m; ++i)
c[i] = create(i);
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... |