#include <doll.h>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
/*void answer(vector<int> c, vector<int> x, vector<int> y)
{
cout << "final : " << c.size() << " " << x.size() << " " << y.size() << endl;
for (int i = 0; i < c.size(); i++) cout << c[i] << "\n";
for (int i = 0; i < x.size(); i++) cout << x[i] << " " << y[i] << "\n";
exit(0);
}*/
const int INF = 1e9;
vector<int> c, x, y;
vector<int> bitreverse(int k)
{
vector<int> c;
for (int i = 0; i < (1 << k); i++)
{
int y = 0;
for (int j = 0; j < k; j++)
{
y = 2 * y + (((1 << j) & i) > 0);
}
c.push_back(y);
}
return c;
}
void build(int f, vector<int> v)
{
//cout << f << " -> ";
//for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
//cout << endl;
if (v.size() == 1)
{
c[f] = v[0];
return;
}
vector<int> nx, ny;
for (int i = 1; i < 20; i++)
{
if (v.size() <= (1 << i))
{
vector<int> tree = {f};
while (tree.size() < (1 << i))
{
tree.push_back(-tree.size());
nx.push_back(-INF);
ny.push_back(-INF);
}
while (tree.size() < 2 * (1 << i))
{
tree.push_back(-INF);
}
vector<int> reach = bitreverse(i);
vector<pair<int, int> > out;
for (int j = 0; j < (1 << i); j++)
{
out.push_back({reach[j], (1 << i) + j});
}
sort(out.begin(), out.end());
int free = (1 << i) - v.size();
for (int j = (1 << i); j < (1 << i) + free; j++)
{
tree[j] = tree[1];
}
int k = 0;
for (int j = 0; j < out.size(); j++)
{
if (tree[out[j].second] == -INF)
{
tree[out[j].second] = v[k];
k++;
}
}
//
vector<int> skip(1 << i);
for (int j = (1 << i) - 1; j >= 1; j--)
{
if (tree[2 * j] == tree[2 * j + 1])
{
skip[-tree[j]] = 1;
tree[j] = tree[2 * j];
}
}
vector<int> new_id(1 << i);
int cc = -1;
for (int j = 1; j < (1 << i); j++)
{
if (skip[j] == 1)
continue;
else
new_id[j] = cc--;
}
int add = x.size();
c[tree[0]] = tree[1] - add;
for (int j = 1; 2 * j < tree.size(); j++)
{
if (j > 1 && tree[j] == tree[2 * j]) continue;
nx[-new_id[-tree[j]] - 1] = (tree[2 * j] < 0 ? new_id[-tree[2 * j]] : tree[2 * j]);
ny[-new_id[-tree[j]] - 1] = (tree[2 * j + 1] < 0 ? new_id[-tree[2 * j + 1]] : tree[2 * j + 1]);
}
for (int j = 0; j < nx.size(); j++)
{
if (nx[j] != -INF)
{
x.push_back(nx[j] - (nx[j] < 0 ? add : 0));
y.push_back(ny[j] - (ny[j] < 0 ? add : 0));
}
}
break;
}
}
}
void create_circuit(int m, vector<int> a)
{
c.resize(m + 1);
a.push_back(0);
build(0, a);
for (int i = 0; i < c.size(); i++) c[i] = -1;
answer(c, x, y);
}
/*int main()
{
int m, n;
cin >> m >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
create_circuit(m, a);
}*/
Compilation message
doll.cpp: In function 'void build(int, std::vector<int>)':
doll.cpp:49:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | if (v.size() <= (1 << i))
| ~~~~~~~~~^~~~~~~~~~~
doll.cpp:52:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
52 | while (tree.size() < (1 << i))
| ~~~~~~~~~~~~^~~~~~~~~~
doll.cpp:58:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
58 | while (tree.size() < 2 * (1 << i))
| ~~~~~~~~~~~~^~~~~~~~~~~~~~
doll.cpp:75:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int j = 0; j < out.size(); j++)
| ~~^~~~~~~~~~~~
doll.cpp:107:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for (int j = 1; 2 * j < tree.size(); j++)
| ~~~~~~^~~~~~~~~~~~~
doll.cpp:113:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for (int j = 0; j < nx.size(); j++)
| ~~^~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:131:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | for (int i = 0; i < c.size(); i++) c[i] = -1;
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
52 ms |
7368 KB |
Output is correct |
3 |
Correct |
49 ms |
7248 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1484 KB |
Output is correct |
6 |
Correct |
63 ms |
8256 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
52 ms |
7368 KB |
Output is correct |
3 |
Correct |
49 ms |
7248 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1484 KB |
Output is correct |
6 |
Correct |
63 ms |
8256 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
90 ms |
13856 KB |
Output is correct |
9 |
Correct |
94 ms |
13980 KB |
Output is correct |
10 |
Correct |
115 ms |
15828 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
52 ms |
7368 KB |
Output is correct |
3 |
Correct |
49 ms |
7248 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1484 KB |
Output is correct |
6 |
Correct |
63 ms |
8256 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
90 ms |
13856 KB |
Output is correct |
9 |
Correct |
94 ms |
13980 KB |
Output is correct |
10 |
Correct |
115 ms |
15828 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
117 ms |
15776 KB |
Output is correct |
15 |
Correct |
92 ms |
13776 KB |
Output is correct |
16 |
Correct |
167 ms |
15648 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
122 ms |
15720 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
68 ms |
12052 KB |
Output is correct |
3 |
Correct |
54 ms |
12012 KB |
Output is correct |
4 |
Correct |
65 ms |
13360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
68 ms |
12052 KB |
Output is correct |
3 |
Correct |
54 ms |
12012 KB |
Output is correct |
4 |
Correct |
65 ms |
13360 KB |
Output is correct |
5 |
Correct |
148 ms |
15632 KB |
Output is correct |
6 |
Correct |
118 ms |
15520 KB |
Output is correct |
7 |
Correct |
123 ms |
15528 KB |
Output is correct |
8 |
Correct |
108 ms |
15536 KB |
Output is correct |
9 |
Correct |
73 ms |
12360 KB |
Output is correct |
10 |
Correct |
120 ms |
15372 KB |
Output is correct |
11 |
Correct |
111 ms |
15468 KB |
Output is correct |
12 |
Correct |
84 ms |
12604 KB |
Output is correct |
13 |
Correct |
119 ms |
13600 KB |
Output is correct |
14 |
Correct |
114 ms |
13716 KB |
Output is correct |
15 |
Correct |
89 ms |
13752 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
65 ms |
8256 KB |
Output is correct |
18 |
Correct |
101 ms |
12616 KB |
Output is correct |
19 |
Correct |
90 ms |
12568 KB |
Output is correct |
20 |
Correct |
129 ms |
15488 KB |
Output is correct |
21 |
Correct |
125 ms |
15408 KB |
Output is correct |
22 |
Correct |
149 ms |
15504 KB |
Output is correct |