#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<" = "<<x<<endl
struct parent
{
int p,edge;
};
vector<int> Exits[1000006];
vector<int> X;
vector<int> Y;
map<int,parent> memo;
int NEXT_FREE_INDEX=1;
void createTree(int root,int i,int lv,int limit,int sum,int unused)
{
if(lv==limit-1){ //Last level of switches
if(unused==1)
X.push_back(-root);
else{
X.push_back(sum);
parent x={i,0};
memo[sum]=x;
}
sum+=(1<<lv);
parent x={i,1};
Y.push_back(sum);
memo[sum]=x;
}
else{
int child_size=(1<<(limit-lv-1));
if(unused>=child_size){ //Drop left child
X.push_back(-root);
Y.push_back(-NEXT_FREE_INDEX);
NEXT_FREE_INDEX++;
createTree(root,NEXT_FREE_INDEX-1,lv+1,limit,sum+(1<<lv),unused-child_size);
}
else{
X.push_back(-NEXT_FREE_INDEX);
NEXT_FREE_INDEX++;
Y.push_back(0);
createTree(root,NEXT_FREE_INDEX-1,lv+1,limit,sum,unused);
Y[i-1]=-NEXT_FREE_INDEX;
NEXT_FREE_INDEX++;
createTree(root,NEXT_FREE_INDEX-1,lv+1,limit,sum+(1<<lv),0);
}
}
}
int logn[200005];
void create_circuit(int m, vector<int> A) {
for(int i=2;i<=200000;i++){
logn[i]=logn[(i+1)/2]+1;
}
int n=A.size();
vector<int> C(m+1);
C[0]=A[0];
for(int i=0;i<n-1;i++){
Exits[ A[i] ].push_back(A[i+1]);
}
Exits[ A[n-1] ].push_back(0);
for(int i=1;i<=m;i++){
if(Exits[i].size()==0) C[i]=0;
else if(Exits[i].size()==1) C[i]=Exits[i][0];
else{ //Create a tree
C[i]=-NEXT_FREE_INDEX;
NEXT_FREE_INDEX++;
int LOG=logn[ Exits[i].size() ];
createTree(-C[i],-C[i],0,LOG,0,(1<<LOG)-Exits[i].size());
int j=0;
for(auto x: memo){
int p=x.second.p;
int edge=x.second.edge;
if(edge==0) X[p-1]=Exits[i][j];
else Y[p-1]=Exits[i][j];
j++;
}
memo.clear();
}
}
/*for(int i=0;i<NEXT_FREE_INDEX;i++){
cout<<X[i]<<" "<<Y[i]<<endl;
}*/
answer(C, X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24524 KB |
Output is correct |
2 |
Correct |
45 ms |
28272 KB |
Output is correct |
3 |
Correct |
55 ms |
27892 KB |
Output is correct |
4 |
Correct |
20 ms |
24556 KB |
Output is correct |
5 |
Correct |
31 ms |
25676 KB |
Output is correct |
6 |
Correct |
71 ms |
29540 KB |
Output is correct |
7 |
Correct |
22 ms |
24492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24524 KB |
Output is correct |
2 |
Correct |
45 ms |
28272 KB |
Output is correct |
3 |
Correct |
55 ms |
27892 KB |
Output is correct |
4 |
Correct |
20 ms |
24556 KB |
Output is correct |
5 |
Correct |
31 ms |
25676 KB |
Output is correct |
6 |
Correct |
71 ms |
29540 KB |
Output is correct |
7 |
Correct |
22 ms |
24492 KB |
Output is correct |
8 |
Correct |
81 ms |
29920 KB |
Output is correct |
9 |
Correct |
87 ms |
30456 KB |
Output is correct |
10 |
Correct |
128 ms |
32880 KB |
Output is correct |
11 |
Correct |
16 ms |
24528 KB |
Output is correct |
12 |
Correct |
22 ms |
24524 KB |
Output is correct |
13 |
Correct |
21 ms |
24472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24524 KB |
Output is correct |
2 |
Correct |
45 ms |
28272 KB |
Output is correct |
3 |
Correct |
55 ms |
27892 KB |
Output is correct |
4 |
Correct |
20 ms |
24556 KB |
Output is correct |
5 |
Correct |
31 ms |
25676 KB |
Output is correct |
6 |
Correct |
71 ms |
29540 KB |
Output is correct |
7 |
Correct |
22 ms |
24492 KB |
Output is correct |
8 |
Correct |
81 ms |
29920 KB |
Output is correct |
9 |
Correct |
87 ms |
30456 KB |
Output is correct |
10 |
Correct |
128 ms |
32880 KB |
Output is correct |
11 |
Correct |
16 ms |
24528 KB |
Output is correct |
12 |
Correct |
22 ms |
24524 KB |
Output is correct |
13 |
Correct |
21 ms |
24472 KB |
Output is correct |
14 |
Correct |
123 ms |
34224 KB |
Output is correct |
15 |
Correct |
78 ms |
29292 KB |
Output is correct |
16 |
Correct |
113 ms |
31872 KB |
Output is correct |
17 |
Correct |
23 ms |
24524 KB |
Output is correct |
18 |
Correct |
19 ms |
24524 KB |
Output is correct |
19 |
Correct |
21 ms |
24524 KB |
Output is correct |
20 |
Correct |
150 ms |
33220 KB |
Output is correct |
21 |
Correct |
22 ms |
24524 KB |
Output is correct |
22 |
Correct |
19 ms |
24564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24524 KB |
Output is correct |
2 |
Correct |
23 ms |
24472 KB |
Output is correct |
3 |
Correct |
17 ms |
24524 KB |
Output is correct |
4 |
Correct |
22 ms |
24524 KB |
Output is correct |
5 |
Correct |
20 ms |
24524 KB |
Output is correct |
6 |
Correct |
17 ms |
24556 KB |
Output is correct |
7 |
Correct |
18 ms |
24564 KB |
Output is correct |
8 |
Correct |
18 ms |
24524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24524 KB |
Output is correct |
2 |
Correct |
135 ms |
35936 KB |
Output is correct |
3 |
Correct |
165 ms |
36284 KB |
Output is correct |
4 |
Correct |
204 ms |
42044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24524 KB |
Output is correct |
2 |
Correct |
135 ms |
35936 KB |
Output is correct |
3 |
Correct |
165 ms |
36284 KB |
Output is correct |
4 |
Correct |
204 ms |
42044 KB |
Output is correct |
5 |
Partially correct |
122 ms |
35116 KB |
Output is partially correct |
6 |
Partially correct |
121 ms |
34904 KB |
Output is partially correct |
7 |
Partially correct |
128 ms |
35072 KB |
Output is partially correct |
8 |
Partially correct |
151 ms |
34236 KB |
Output is partially correct |
9 |
Partially correct |
96 ms |
32192 KB |
Output is partially correct |
10 |
Partially correct |
181 ms |
36812 KB |
Output is partially correct |
11 |
Partially correct |
125 ms |
32864 KB |
Output is partially correct |
12 |
Partially correct |
109 ms |
30024 KB |
Output is partially correct |
13 |
Partially correct |
90 ms |
31272 KB |
Output is partially correct |
14 |
Partially correct |
88 ms |
31408 KB |
Output is partially correct |
15 |
Partially correct |
90 ms |
31456 KB |
Output is partially correct |
16 |
Partially correct |
22 ms |
24652 KB |
Output is partially correct |
17 |
Partially correct |
83 ms |
29700 KB |
Output is partially correct |
18 |
Partially correct |
87 ms |
30532 KB |
Output is partially correct |
19 |
Partially correct |
86 ms |
29728 KB |
Output is partially correct |
20 |
Partially correct |
132 ms |
32480 KB |
Output is partially correct |
21 |
Partially correct |
115 ms |
32488 KB |
Output is partially correct |
22 |
Partially correct |
123 ms |
32232 KB |
Output is partially correct |