#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
const int maxn5 = 1e6 + 10;
int newnode = 0, ind[maxn5], sz[maxn5], need = 0, val[maxn5];
vector <int> c, x, y, tmp1, tmp2, adj1, adj2;
vector <pair<int, pair<int, int>>> av;
void build(int lev){
tmp1.clear();
tmp1.pb(0);
newnode = 1;
adj1.pb(0); adj2.pb(0);
lev--;
for(int i = 0; i < lev; i++){
tmp2.clear();
for(auto u : tmp1)
tmp2.pb(u);
tmp1.clear();
for(auto u : tmp2){
tmp1.pb(newnode);
tmp1.pb(newnode + 1);
val[newnode] = val[u];
val[newnode + 1] = val[u] + (1 << i);
adj1[u] = newnode++;
adj2[u] = newnode++;
adj1.pb(0); adj1.pb(0);
adj2.pb(0); adj2.pb(0);
}
}
}
void dfs(int v){
if(adj1[v] == 0){
if(need >= 2){
sz[v] = 0;
need -= 2;
adj1[v] = adj2[v] = -1;
}
else if(need == 1){
sz[v] = 1;
need--;
adj1[v] = -1;
}
else
sz[v] = 2;
return;
}
dfs(adj1[v]);
dfs(adj2[v]);
sz[v] = sz[adj1[v]] + sz[adj2[v]];
if(!sz[adj1[v]])
adj1[v] = -1;
if(!sz[adj2[v]])
adj2[v] = -1;
}
void create_circuit(int m, std::vector<int> a) {
int n = a.size();
if(n == 1){
c.pb(a[0]);
for(int i = 0; i < m; i++)
c.pb(0);
answer(c, x, y);
return;
}
int lg = 1;
while((1 << lg) < n)
lg++;
build(lg);
need = (1 << lg) - n;
dfs(0);
av.clear();
int id = 0;
/*
cout << need << endl;
for(int i = 0; i < newnode; i++)
cout << i << ' ' << sz[i] << ' ' << adj1[i] << ' ' << adj2[i] << endl;
//*/
for(int i = 0; i < newnode; i++) if(sz[i]){
x.pb(0);
y.pb(0);
ind[i] = id++;
}
for(int i = 0; i < newnode; i++) if(sz[i]){
if(adj1[i] > 0)
x[ind[i]] = -(1 + ind[adj1[i]]);
else if(adj1[i] == 0)
av.pb({val[i], {ind[i], 0}});
else
x[ind[i]] = -1;
if(adj2[i] > 0)
y[ind[i]] = -(1 + ind[adj2[i]]);
else if(adj2[i] == 0)
av.pb({val[i] + (1 << (lg - 1)), {ind[i], 1}});
else
y[ind[i]] = -1;
}
sort(all(av));
c.pb(a[0]);
for(int i = 0; i < m; i++)
c.pb(-1);
a.pb(0);
for(int i = 0; i < n; i++){
if(av[i].se.se)
y[av[i].se.fi] = a[i + 1];
else
x[av[i].se.fi] = a[i + 1];
}
answer(c, x, y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
6764 KB |
Output is correct |
3 |
Correct |
26 ms |
7996 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
1612 KB |
Output is correct |
6 |
Correct |
42 ms |
10432 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
6764 KB |
Output is correct |
3 |
Correct |
26 ms |
7996 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
1612 KB |
Output is correct |
6 |
Correct |
42 ms |
10432 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
45 ms |
12332 KB |
Output is correct |
9 |
Correct |
51 ms |
15788 KB |
Output is correct |
10 |
Correct |
75 ms |
19764 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
31 ms |
6764 KB |
Output is correct |
3 |
Correct |
26 ms |
7996 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
10 ms |
1612 KB |
Output is correct |
6 |
Correct |
42 ms |
10432 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
45 ms |
12332 KB |
Output is correct |
9 |
Correct |
51 ms |
15788 KB |
Output is correct |
10 |
Correct |
75 ms |
19764 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
75 ms |
19284 KB |
Output is correct |
15 |
Correct |
47 ms |
15044 KB |
Output is correct |
16 |
Correct |
73 ms |
18896 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
78 ms |
19436 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
39 ms |
9840 KB |
Output is correct |
3 |
Correct |
41 ms |
12972 KB |
Output is correct |
4 |
Correct |
64 ms |
16380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
39 ms |
9840 KB |
Output is correct |
3 |
Correct |
41 ms |
12972 KB |
Output is correct |
4 |
Correct |
64 ms |
16380 KB |
Output is correct |
5 |
Correct |
73 ms |
18832 KB |
Output is correct |
6 |
Correct |
72 ms |
18572 KB |
Output is correct |
7 |
Correct |
73 ms |
18548 KB |
Output is correct |
8 |
Correct |
69 ms |
18392 KB |
Output is correct |
9 |
Correct |
41 ms |
13868 KB |
Output is correct |
10 |
Correct |
73 ms |
18424 KB |
Output is correct |
11 |
Correct |
66 ms |
18188 KB |
Output is correct |
12 |
Correct |
42 ms |
14132 KB |
Output is correct |
13 |
Correct |
51 ms |
11184 KB |
Output is correct |
14 |
Correct |
49 ms |
14980 KB |
Output is correct |
15 |
Correct |
45 ms |
14976 KB |
Output is correct |
16 |
Correct |
2 ms |
836 KB |
Output is correct |
17 |
Correct |
41 ms |
11060 KB |
Output is correct |
18 |
Correct |
46 ms |
10928 KB |
Output is correct |
19 |
Correct |
42 ms |
14088 KB |
Output is correct |
20 |
Correct |
70 ms |
18292 KB |
Output is correct |
21 |
Correct |
67 ms |
18112 KB |
Output is correct |
22 |
Correct |
66 ms |
18204 KB |
Output is correct |