이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "doll.h"
//#include "debug.cpp"
#define debug(...) 0
using namespace std;
vector<int> x, y, c, state, order;
vector<array<int, 2>> in;
int t = 0;
int tree(vector<int> nodes){
// nodes.size() must be a power of 2
// returns id of exit node
while(nodes.size()>1){
vector<int> nnodes;
for(int i=0; i<nodes.size(); i+=2){
x.push_back(nodes[i]);
y.push_back(nodes[i+1]);
state.push_back(0);
nnodes.push_back(-x.size());
if(nodes[i]>=0){
in[nodes[i]]={-int(x.size()), 0};
}
if(nodes[i+1]>=0){
in[nodes[i+1]]={-int(x.size()), 1};
}
}
swap(nodes, nnodes);
}
return nodes.front();
}
void sim(int u){
if(u>=0){
if(order[u]!=-1){
return;
}
order[u]=t++;
sim(c[u]);
}else{
u = -u-1;
if(state[u]==0){
state[u]^=1;
sim(x[u]);
}else{
state[u]^=1;
sim(y[u]);
}
}
}
void create_circuit(int M, std::vector<int> A) {
int n = A.size(), now = 1;
vector<int> roots(20);
in.assign(n+1, {});
for(int i=0; i<20; i++){
if(n&(1<<i)){
vector<int> nodes(1<<i);
iota(nodes.begin(), nodes.end(), now);
roots[i]=tree(nodes);
now += 1<<i;
}
}
// make switcher
int len = log2(n) + 1;
int start = -x.size()-1;
for(int i=0; i<len; i++){
if(roots[len - i - 1]){
x.push_back(roots[len - i - 1]);
y.push_back(-x.size() - 1);
state.push_back(0);
if(roots[len - i - 1]>=0){
in[roots[len - i - 1]] = {-int(x.size()), 0};
}
}else{
x.push_back(start);
y.push_back(-x.size() - 1);
state.push_back(0);
}
}
c.assign(M+1, start);
order.assign(n+1, -1);
y.back() = 0;
c[0]=start;
vector<array<int, 2>> rev(n+1);
sim(start);
for(int i=0; i<order.size(); i++){
rev[order[i]] = in[i];
}
debug(order);
debug(c);
debug(x);
debug(y);
debug(in);
debug(rev);
for(int i=0; i<n; i++){
auto [module, side] = rev[i];
module = -module - 1;
if(side==0){
x[module] = A[i];
}else{
y[module] = A[i];
}
}
debug(c);
debug(x);
debug(y);
answer(c, x, y);
}
컴파일 시 표준 에러 (stderr) 메시지
doll.cpp: In function 'int tree(std::vector<int>)':
doll.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i=0; i<nodes.size(); i+=2){
| ~^~~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:94:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int i=0; i<order.size(); i++){
| ~^~~~~~~~~~~~~
doll.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 0
| ^
doll.cpp:97:5: note: in expansion of macro 'debug'
97 | debug(order);
| ^~~~~
doll.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 0
| ^
doll.cpp:98:5: note: in expansion of macro 'debug'
98 | debug(c);
| ^~~~~
doll.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 0
| ^
doll.cpp:99:5: note: in expansion of macro 'debug'
99 | debug(x);
| ^~~~~
doll.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 0
| ^
doll.cpp:100:5: note: in expansion of macro 'debug'
100 | debug(y);
| ^~~~~
doll.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 0
| ^
doll.cpp:101:5: note: in expansion of macro 'debug'
101 | debug(in);
| ^~~~~
doll.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 0
| ^
doll.cpp:102:5: note: in expansion of macro 'debug'
102 | debug(rev);
| ^~~~~
doll.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 0
| ^
doll.cpp:114:5: note: in expansion of macro 'debug'
114 | debug(c);
| ^~~~~
doll.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 0
| ^
doll.cpp:115:5: note: in expansion of macro 'debug'
115 | debug(x);
| ^~~~~
doll.cpp:5:20: warning: statement has no effect [-Wunused-value]
5 | #define debug(...) 0
| ^
doll.cpp:116:5: note: in expansion of macro 'debug'
116 | debug(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... |