이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "doll.h"
#include <vector>
void create_circuit(int M, std::vector<int> A);
void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define out(x) "{" << (#x) << ": " << x << "} "
const int WRONG_ID = -16969420, ROOT_ID = WRONG_ID + 1;
vector<int> arr;
vector<int> x, y;
pair<int, int> buildTree(int l, int r) {
if(l == r) {
//cout << l << " " << r << " " << out(arr[l]) << endl;
return {arr[l], arr[l] != WRONG_ID};
}
int m = (l + r) / 2ll;
auto lftSon = buildTree(l, m);
auto rghtSon = buildTree(m + 1, r);
//cout << l << " " << r << " " << lftSon << " " << rghtSon << endl;
if(lftSon.second + rghtSon.second == 0) {
return {WRONG_ID, 0};
} else {
x.push_back(lftSon.first);
y.push_back(rghtSon.first);
return {-x.size(), lftSon.second + rghtSon.second};
}
}
int bitInverse(int ind, int pow2) {
int ret = 0;
for(int i = 0; i < pow2; i ++) {
if(ind & (1 << i)) {
ret |= (1 << (pow2 - 1 - i));
}
}
return ret;
}
void create_circuit(int M, std::vector<int> A) {
assert(M < 5);
arr = A;
arr.push_back(WRONG_ID);
int pow2 = 0;
while((1 << pow2) < arr.size()) {
pow2 ++;
}
while(arr.size() < (1 << pow2)) {
arr.push_back(WRONG_ID);
}
arr[arr.size() - 1] = 0;
vector<pair<int, int> > prs;
for(int i = 0; i < arr.size(); i ++) {
int inv = bitInverse(i, pow2);
if(i < A.size()) {
prs.push_back({inv, -1});
//cout << out(prs.back()) << endl;
}
}
sort(prs.begin(), prs.end());
for(int i = 0; i < prs.size(); i ++) {
prs[i].second = arr[i];
}
for(int i = 0; i < prs.size(); i ++) {
arr[bitInverse(prs[i].first, pow2)] = prs[i].second;
}
pow2 = 1 << pow2;
int root = buildTree(0, pow2 - 1).first;
vector<int> ptr;
for(int i = 0; i <= M; i ++) {
ptr.push_back(root);
}
for(int i = 0; i < x.size(); i ++) {
if(x[i] == WRONG_ID) {
x[i] = root;
}
if(y[i] == WRONG_ID) {
y[i] = root;
}
//cout << -i - 1 << " " << x[i] << " " << y[i] << endl;
}
answer(ptr, x, y);
}
컴파일 시 표준 에러 (stderr) 메시지
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | while((1 << pow2) < arr.size()) {
| ~~~~~~~~~~~~^~~~~~~~~~~~
doll.cpp:63:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
63 | while(arr.size() < (1 << pow2)) {
| ~~~~~~~~~~~^~~~~~~~~~~~~
doll.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i = 0; i < arr.size(); i ++) {
| ~~^~~~~~~~~~~~
doll.cpp:70:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | if(i < A.size()) {
| ~~^~~~~~~~~~
doll.cpp:76:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 0; i < prs.size(); i ++) {
| ~~^~~~~~~~~~~~
doll.cpp:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 0; i < prs.size(); i ++) {
| ~~^~~~~~~~~~~~
doll.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int i = 0; i < x.size(); i ++) {
| ~~^~~~~~~~~~
# | 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... |