이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "doll.h"
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
const int MAX = 1e9;
vector<int> x, y, arr;
int solve(vector<int> idx) {
assert(idx.size());
if ((int)count(all(idx), -1) == (int)idx.size()) {
return -1;
}
if (idx.size() == 1) {
assert(idx[0] >= 0);
return idx[0] == (int)arr.size() ? 0 : arr[idx[0]];
}
x.push_back(0), y.push_back(0);
int v = -(int)x.size();
// cout << v << ": ";
// for (int e : idx) {
// cout << e << " ";
// }
// cout << endl;
vector<int> lef, rig;
for (int e : idx) {
if ((2 * lef.size() + 2 <= idx.size() && e < 0) || lef.size() <= rig.size()) {
lef.push_back(e);
} else {
rig.push_back(e);
}
}
// cout << "div " << idx.size() << " " << lef.size() << " " << rig.size() << endl;
// for (int i = 0; i < (int)idx.size(); ++i) {
// (i % 2 ? rig : lef).push_back(idx[i]);
// }
assert(0 <= -1 - v && -1 - v < (int)x.size());
assert(0 <= -1 - v && -1 - v < (int)y.size());
int a = solve(lef), b = solve(rig);
x[-1 - v] = a;
y[-1 - v] = b;
return v;
}
void create_circuit(int m, vector<int> a) {
arr = a;
vector<int> c(m + 1, -1), idx((int)a.size() + 1);
iota(all(idx), 0);
reverse(all(idx));
while (idx.size() & (idx.size() - 1)) {
idx.push_back(-1);
}
reverse(all(idx));
int root = solve(idx);
assert(root == -1);
// cout << "===" << endl;
// for (int e : x) {
// cout << e << " ";
// }
// cout << endl;
// for (int e : y) {
// cout << e << " ";
// }
// cout << endl;
answer(c, x, y);
}
#ifdef LC
#include "grader.cpp"
#endif
# | 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... |