#include "doll.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7;
void create_circuit(int m, vi a) {
a.PB(0);
int n = SZ(a);
vi x, y;
int sz = 0;
function<pair<int, V<pi>>(int, int)> dfs = [&] (int n, int m) -> pair<int, V<pi>> {
assert(n >= 1);
x.PB(0), y.PB(0);
int u = -(++sz);
V<pi> res;
if(m == 2) {
if(n == 1) res.EB(u, 0), res.EB(u, 3);
else res.EB(u, 0), res.EB(u, 1);
} else {
int rsz = min(n, m / 2);
int ul, ur;
V<pi> resl, resr;
tie(ur, resr) = dfs(rsz, m / 2);
y[-u - 1] = ur;
if(n - rsz) {
tie(ul, resl) = dfs(n - rsz, m / 2);
x[-u - 1] = ul;
} else {
for(int i = 0; i < m / 2; i++)
resl.EB(u, 2);
}
for(int i = 0; i < m / 2; i++) {
res.PB(resl[i]);
res.PB(resr[i]);
}
}
assert(SZ(res) == m);
return {u, res};
};
int mm = 1;
while(mm < n) mm *= 2;
auto [u, tt] = dfs(n, mm);
x.resize(sz), y.resize(sz);
int i = 0;
for(auto[who, tp]:tt) {
if(tp == 0) {
x[-who - 1] = a[i++];
} else if(tp == 1) {
y[-who - 1] = a[i++];
} else if(tp == 2) {
x[-who - 1] = u;
} else {
y[-who - 1] = u;
}
}
assert(i == n);
vi c(m + 1, u);
// for(int i = 0; i < SZ(x); i++)
// cerr << -(i + 1) << ": " << x[i] << " " << y[i] << endl;
answer(c, x, y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, vi)':
doll.cpp:56:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | auto [u, tt] = dfs(n, mm);
| ^
doll.cpp:59:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
59 | for(auto[who, tp]:tt) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
45 ms |
5424 KB |
Output is correct |
3 |
Correct |
34 ms |
4880 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
1364 KB |
Output is correct |
6 |
Correct |
52 ms |
6940 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
45 ms |
5424 KB |
Output is correct |
3 |
Correct |
34 ms |
4880 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
1364 KB |
Output is correct |
6 |
Correct |
52 ms |
6940 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
69 ms |
8520 KB |
Output is correct |
9 |
Correct |
80 ms |
9032 KB |
Output is correct |
10 |
Correct |
97 ms |
12136 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
45 ms |
5424 KB |
Output is correct |
3 |
Correct |
34 ms |
4880 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
9 ms |
1364 KB |
Output is correct |
6 |
Correct |
52 ms |
6940 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
69 ms |
8520 KB |
Output is correct |
9 |
Correct |
80 ms |
9032 KB |
Output is correct |
10 |
Correct |
97 ms |
12136 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
94 ms |
11672 KB |
Output is correct |
15 |
Correct |
75 ms |
8424 KB |
Output is correct |
16 |
Correct |
97 ms |
11412 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
92 ms |
11868 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
60 ms |
8520 KB |
Output is correct |
3 |
Correct |
63 ms |
8484 KB |
Output is correct |
4 |
Correct |
96 ms |
9844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
60 ms |
8520 KB |
Output is correct |
3 |
Correct |
63 ms |
8484 KB |
Output is correct |
4 |
Correct |
96 ms |
9844 KB |
Output is correct |
5 |
Correct |
94 ms |
11284 KB |
Output is correct |
6 |
Correct |
92 ms |
10904 KB |
Output is correct |
7 |
Correct |
90 ms |
11012 KB |
Output is correct |
8 |
Correct |
97 ms |
10648 KB |
Output is correct |
9 |
Correct |
57 ms |
8492 KB |
Output is correct |
10 |
Correct |
86 ms |
10576 KB |
Output is correct |
11 |
Correct |
85 ms |
10308 KB |
Output is correct |
12 |
Correct |
60 ms |
8528 KB |
Output is correct |
13 |
Correct |
61 ms |
8516 KB |
Output is correct |
14 |
Correct |
60 ms |
8528 KB |
Output is correct |
15 |
Correct |
63 ms |
8432 KB |
Output is correct |
16 |
Correct |
4 ms |
596 KB |
Output is correct |
17 |
Correct |
61 ms |
6264 KB |
Output is correct |
18 |
Correct |
60 ms |
8420 KB |
Output is correct |
19 |
Correct |
57 ms |
8432 KB |
Output is correct |
20 |
Correct |
88 ms |
10520 KB |
Output is correct |
21 |
Correct |
106 ms |
10240 KB |
Output is correct |
22 |
Correct |
84 ms |
10256 KB |
Output is correct |