#include "doll.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
if(pvaspace) b << " "; pvaspace=true;\
b << pva;\
}\
b << "\n";}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;
const ll MOD = 1000000007;
const ll MAX = 2147483647;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
ll ifloor(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a < 0) return (a - b + 1) / b;
else return a / b;
}
ll iceil(ll a, ll b){
if(b < 0) a *= -1, b *= -1;
if(a > 0) return (a + b - 1) / b;
else return a / b;
}
vector<int> x(1, MAX), y(1, MAX);
vector<int> a;
int ts = -1;
int n;
vector<pair<int, pii>> leaf;
int dfs(int id, int dpt, int num, pii from){
if(dpt == __lg(n - 1) + 1){
leaf.eb(mp(num, from));
return MAX;
}
if(id == MAX){
id = --ts;
x.eb(MAX);
y.eb(MAX);
}
if(leaf.size() < n){
int tmp = dfs(y[-id - 1], dpt + 1, num + (1 << dpt), mp(-id - 1, 1));
y[-id - 1] = tmp;
}
if(leaf.size() < n){
int tmp = dfs(x[-id - 1], dpt + 1, num, mp(-id - 1, 0));
x[-id - 1] = tmp;
}
return id;
}
void create_circuit(int m, vector<int> _a){
a = _a;
vector<int> c(m + 1, -1);
c[0] = a[0];
a.erase(a.begin());
a.eb(0);
n = a.size();
dfs(-1, 0, 0, mp(0, 0));
lsort(leaf);
// printv(leaf, cerr);
for(int i = 0; i < n; i++){
if(leaf[i].S.S == 0) x[leaf[i].S.F] = a[i];
else y[leaf[i].S.F] = a[i];
}
for(int i = 0; i < x.size(); i++){
if(x[i] == MAX) x[i] = -1;
if(y[i] == MAX) y[i] = -1;
}
// printv(x, cerr);
// printv(y, cerr);
// printv(c, cerr);
answer(c, x, y);
}
Compilation message
doll.cpp: In function 'int dfs(int, int, int, pii)':
doll.cpp:80:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
80 | if(leaf.size() < n){
| ~~~~~~~~~~~~^~~
doll.cpp:84:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
84 | if(leaf.size() < n){
| ~~~~~~~~~~~~^~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:108:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | for(int i = 0; i < x.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
39 ms |
4592 KB |
Output is correct |
3 |
Correct |
37 ms |
4580 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1356 KB |
Output is correct |
6 |
Correct |
57 ms |
6856 KB |
Output is correct |
7 |
Correct |
1 ms |
232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
39 ms |
4592 KB |
Output is correct |
3 |
Correct |
37 ms |
4580 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1356 KB |
Output is correct |
6 |
Correct |
57 ms |
6856 KB |
Output is correct |
7 |
Correct |
1 ms |
232 KB |
Output is correct |
8 |
Correct |
65 ms |
8340 KB |
Output is correct |
9 |
Correct |
71 ms |
8660 KB |
Output is correct |
10 |
Correct |
105 ms |
12632 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
39 ms |
4592 KB |
Output is correct |
3 |
Correct |
37 ms |
4580 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1356 KB |
Output is correct |
6 |
Correct |
57 ms |
6856 KB |
Output is correct |
7 |
Correct |
1 ms |
232 KB |
Output is correct |
8 |
Correct |
65 ms |
8340 KB |
Output is correct |
9 |
Correct |
71 ms |
8660 KB |
Output is correct |
10 |
Correct |
105 ms |
12632 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
104 ms |
12252 KB |
Output is correct |
15 |
Correct |
63 ms |
7956 KB |
Output is correct |
16 |
Correct |
103 ms |
12184 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
103 ms |
12440 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
62 ms |
7072 KB |
Output is correct |
3 |
Correct |
59 ms |
7112 KB |
Output is correct |
4 |
Correct |
101 ms |
10700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
62 ms |
7072 KB |
Output is correct |
3 |
Correct |
59 ms |
7112 KB |
Output is correct |
4 |
Correct |
101 ms |
10700 KB |
Output is correct |
5 |
Correct |
103 ms |
11944 KB |
Output is correct |
6 |
Correct |
101 ms |
11736 KB |
Output is correct |
7 |
Correct |
100 ms |
11884 KB |
Output is correct |
8 |
Correct |
103 ms |
11596 KB |
Output is correct |
9 |
Correct |
60 ms |
7072 KB |
Output is correct |
10 |
Correct |
96 ms |
11460 KB |
Output is correct |
11 |
Correct |
97 ms |
11084 KB |
Output is correct |
12 |
Correct |
61 ms |
7340 KB |
Output is correct |
13 |
Correct |
61 ms |
7764 KB |
Output is correct |
14 |
Correct |
64 ms |
7868 KB |
Output is correct |
15 |
Correct |
69 ms |
8012 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
69 ms |
7392 KB |
Output is correct |
18 |
Correct |
79 ms |
7312 KB |
Output is correct |
19 |
Correct |
60 ms |
7392 KB |
Output is correct |
20 |
Correct |
102 ms |
11360 KB |
Output is correct |
21 |
Correct |
96 ms |
11076 KB |
Output is correct |
22 |
Correct |
97 ms |
11228 KB |
Output is correct |