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>
#include "doll.h"
using namespace std;
#define rep(i,a,b) for(int i = a; i<b; ++i)
using vi = vector<int>;
void create_circuit(int m, vi a) {
a.push_back(0);
int n = a.size();
int nn = (n+1)/2;
vi x(nn),y(nn);
auto add = [&](int e1, int e2) {
y.push_back(-e1-1);
x.push_back(-e2-1);
};
int l = 0, r = nn;
while(r-l != 1) {
for(; l+1 < r; l+=2) add(l, l+1);
if(l < r) add(l++, -1);
r = x.size();
}
rep(i,0,r) {
if(x[i] == 0) x[i] = -r;
if(y[i] == 0) y[i] = -r;
}
vi c(m+1, -r);
int cnt = 0;
int node = 0;
vi state(x.size(), 0);
int stCount = 0;
while(cnt < n) {
if(node < 0) {
node = -node-1;
state[node] = 1-state[node];
stCount += 2*state[node]-1;
int& nxt = state[node] ? x[node] : y[node];
if(node < nn) {
if(cnt < n-1 || stCount == 0)
nxt = a[cnt++];
}
node = nxt;
}
else node = c[node];
}
// rep(i,0,m+1) cout << i << " " << c[i] << endl;
// rep(i,0,r) cout << -(i+1) << " " << x[i] << " " << y[i] << endl;
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... |