이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include <bits/stdc++.h>
const int UNASSINED = 1'000'000'000;
const int ROOT = 1'000'000'001;
using vi = std::vector<int>;
vi create_level(const vi& last_level, vi& X, vi& Y, int& S) {
vi new_level;
for(size_t i = 0; i < last_level.size(); i+=2) {
if(i+1 < last_level.size()) {
X.push_back(last_level[i]);
Y.push_back(last_level[i+1]);
} else {
X.push_back(ROOT);
Y.push_back(last_level[i]);
}
new_level.push_back(-1 * (++S));
}
return new_level;
}
int& simulate_untill_next_unassined(int cur_switch, vi& state, vi& X, vi& Y) {
while(true) {
int idx = -cur_switch - 1;
int* ptr = state[idx] ? &X[idx] : &Y[idx];
state[idx] ^= 1;
int& val = *ptr;
if(val == UNASSINED) return val;
assert(val < 0);
cur_switch = val;
}
}
void create_circuit(int M, std::vector<int> A) {
const int N = A.size();
// create tree with N leefs
vi X, Y;
vi last_level(N, UNASSINED);
int S = 0;
while(last_level.size() != 1)
last_level = create_level(last_level, X, Y, S);
int root = -S;
assert(last_level.back() == root);
for(int i = 0; i < S; i++)
if(X[i]==ROOT)
X[i] = root;
vi C(M + 1, root);
C[0] = A[0]; // first go to A0, and than everyone goes to root.
vi state(S);
for(int i = 1; i < N; i++) {
int& v = simulate_untill_next_unassined(root, state, X, Y);
v = A[i];
}
int& last_v = simulate_untill_next_unassined(root, state, X, Y);
last_v = 0;
for(int i : state) assert(i == 0);
for(int i : X) assert(i != UNASSINED);
for(int i : Y) assert(i != UNASSINED);
assert(X.size() == S);
assert(Y.size() == S);
answer(C, X, Y);
}
컴파일 시 표준 에러 (stderr) 메시지
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from doll.cpp:2:
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:62:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
62 | assert(X.size() == S);
| ~~~~~~~~~^~~~
doll.cpp:63:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
63 | assert(Y.size() == S);
| ~~~~~~~~~^~~~
# | 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... |