이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> C, X, Y, A;
int N, M;
int id;
int x[202020];
int y[202020];
int s[202020];
int mid = 0;
int build2k(int b) {
int now = ++id;
if(b == 2) {
x[now] = y[now] = -1; return now;
}
x[now] = build2k(b / 2);
y[now] = build2k(b / 2);
return now;
}
int build(int n, int b) {
//printf("%d %d\n", n, b);
int now = ++id;
if(n == 1 && b == 1) {
x[now] = 1;
y[now] = -1;
return now;
}
if(n == b) {
x[now] = 1;
y[now] = build2k(b);
return now;
}
if(n < b) {
x[now] = 1;
y[now] = build(n, b / 2);
return now;
}
x[now] = build2k(b);
y[now] = build(n - b, b / 2);
return now;
}
void simu() {
int now = 1;
while(1) {
s[now] = !s[now];
if(!s[now]) { /// y
if(y[now] == -1) {
--mid;
if(mid < -N + 1) { y[now] = 0; return; }
else y[now] = -A[-mid - 1];
now = 1;
}
else now = y[now];
}
else { /// x
if(x[now] == -1) {
--mid;
if(mid < -N + 1) { x[now] = 0; return; }
else x[now] = -A[-mid - 1];
now = 1;
}
else now = x[now];
}
}
}
void create_circuit(int _M, std::vector<int> _A) {
_A.push_back(0);
A = _A;
N = A.size();
M = _M;
if(N == 2) {
C.resize(M + 1);
C[0] = C[A[0]] = -1;
X.push_back(A[0]);
Y.push_back(0);
answer(C, X, Y);
return;
}
int b = 1; while(b * 2 <= N) b <<= 1;
build(N, b);
simu();
for(int i = 0; i <= M; i++) C.push_back(-1);
for(int i = 1; i <= id; i++) {
X.push_back(-x[i]);
Y.push_back(-y[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... |