이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<ll , ll> ii;
#define ff first
#define ss second
#define pb push_back
const ll N = 1e6 + 5;
vector < ll > v[N];
vector < ll > g[N];
ll S = 0;
ll col[N];
vector < ll > child;
vector < ll > X,Y;
void setX(ll i, ll x){
X[abs(i) - 1] = x;
return;
}
void setY(ll i, ll y){
Y[abs(i) - 1] = y;
return;
}
ll tot = 0;
ll breakdown(ll sz){
if(sz == 2){
S--;
X.pb(0); Y.pb(0);
tot += 2;
return S;
}
ll node = S - 1; S--; X.pb(0); Y.pb(0);
ll n1 = breakdown(sz/2);
ll n2 = breakdown(sz/2);
g[-node].pb(-n1);
g[-node].pb(-n2);
setX(node, n1);
setY(node, n2);
return node;
}
void go(ll node, ll sz){
if(sz == 2){
child.pb(node); col[-node] ^= 1;
return;
}
if(col[-node]) go(-g[-node][1], sz/2);
else go(-g[-node][0], sz/2);
col[-node] ^= 1;
return;
}
void create_circuit(int M, std::vector<int> A) {
memset(col, 0, sizeof(col));
ll n = A.size();
A.pb(0);
for(ll i = 0; i < n; i++){
v[A[i]].pb(A[i + 1]);
}
ll m = M;
vector < ll > C(m + 1); C[0] = A[0];
for(ll i = 1; i <= m; i++){
if(v[i].size() == 0){
C[i] = 0;
continue;
}
if(v[i].size() == 1){
C[i] = v[i][0];
continue;
}
ll two = 1; ll d = 1;
while(two * 2 < v[i].size()) two *= 2, d++;
two *= 2;
child.clear(); tot = 0;
ll root = breakdown(two);
C[i] = root;
while(tot--) go(root, two);
ll rem = child.size();
ll cur = 0;
for(ll j = 0; j < child.size(); j++){
if(rem > v[i].size()){
if(col[-child[j]]) setY(child[j], root);
else setX(child[j], root);
}else{
if(col[-child[j]]) setY(child[j], v[i][cur]);
else setX(child[j], v[i][cur]);
cur++;
}
col[-child[j]] ^= 1;
rem--;
}
}
#ifdef LOCAL
for(ll i = 0; i <= m; i++){
cout << C[i] << ' ';
}
cout << '\n';
for(ll i = 0; i < X.size(); i++){
cout << -(i + 1) << ' ' << X[i] << ' ' << Y[i] << '\n';
}
#endif
answer(C, X, Y);
}
컴파일 시 표준 에러 (stderr) 메시지
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:78:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | while(two * 2 < v[i].size()) two *= 2, d++;
| ~~~~~~~~^~~~~~~~~~~~~
doll.cpp:86:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(ll j = 0; j < child.size(); j++){
| ~~^~~~~~~~~~~~~~
doll.cpp:87:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | if(rem > v[i].size()){
| ~~~~^~~~~~~~~~~~~
# | 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... |