This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
const int INF = 2e9;
vector<int> C, X, Y;
int cnt = 0;
int get_switch(int x, int y) {
X.push_back(x);
Y.push_back(y);
return --cnt;
}
int create_tree(const vector<int> &v) {
bool ok = true;
for (int i = 0; i < (int)v.size()-1; ++i) {
if (v[i] != v[i+1])
ok = false;
}
if (ok)
return v[0];
vector<int> vx, vy;
for (int i = 0; i < v.size(); ++i) {
if (i % 2 == 0)
vx.push_back(v[i]);
else
vy.push_back(v[i]);
}
int x = create_tree(vx);
int y = create_tree(vy);
return get_switch(x, y);
}
int reverse_bit(int k, int a) {
int b = 0;
while (k--) {
b <<= 1;
b |= (a&1);
a >>= 1;
}
return b;
}
void create_circuit(int M, vector<int> A) {
// find k
int n = A.size();
int k = 0;
while ((1<<k) < n)
++k;
vector<int> v(1<<k, 0);
for (int i = 0; i < (1<<k)-n; ++i)
v[reverse_bit(k, i)] = INF;
int cnt = 0;
for (int i = 1; i < n; ++i) {
while (cnt < v.size() && v[cnt] != 0) ++cnt;
v[cnt] = A[i];
}
n = 1<<k;
v[n-1] = 0;
int r = create_tree(v);
C = vector<int>(M+1, r);
C[0] = A[0];
for (auto &x: X) {
if (x == INF)
x = r;
}
for (auto &y: Y) {
if (y == INF)
y = r;
}
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'int create_tree(const std::vector<int>&)':
doll.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | while (cnt < v.size() && v[cnt] != 0) ++cnt;
| ~~~~^~~~~~~~~~
# | 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... |