이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
int idd;
int n, m;
vector<int> a;
vector<int> state;
vector<int> c, x, y;
void build(int nd, int l, int r, int elements) {
//cerr << "nd, l, r: " << nd << ' ' << l << ' ' << r << endl;
//if (r - l == 1) {
//return;
//}
assert(l != r);
int sz = 1;
while (sz * 2 < elements) {
sz *= 2;
}
int mid = (l + r) >> 1;
if (mid + 1 < r) {
int rx = --idd;
x.push_back(0);
y.push_back(0);
y[-nd - 1] = rx;
build(rx, mid + 1, r, sz);
}
if (sz == elements) {
x[-nd - 1] = -1; //go back to the root
//cerr << "nd: " << nd << endl;
} else if (l < mid) {
int lx = --idd;
x.push_back(0);
y.push_back(0);
x[-nd - 1] = lx;
build(lx, l, mid, elements - sz);
}
}
void dfs(int v, int ptr) {
//cerr << "V, ptr: " << v << ' ' << ptr << endl;
if (v == 0) {
//assert(ptr == n);
return;
}
if (v > 0) {
dfs(c[v], ptr + 1);
} else {
if (state[-v - 1] == 0) {
if (!x[-v - 1]) {
x[-v - 1] = a[ptr];
}
state[-v - 1] ^= 1;
dfs(x[-v - 1], ptr);
} else {
if (!y[-v - 1]) {
y[-v - 1] = a[ptr];
}
state[-v - 1] ^= 1;
dfs(y[-v - 1], ptr);
}
}
}
void create_circuit(int m_, vector<int> a_) {
m = m_;
a = a_;
a.push_back(0);
n = (int) a.size();
idd = -1;
x.push_back(0);
y.push_back(0);
int b = 1;
while (b < n) {
b *= 2;
}
build(-1, 0, b - 1, n);
c.assign(m + 1, -1);
state.resize(-idd);
dfs(-1, 0);
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... |