#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<" = "<<x<<endl
struct parent
{
int p;
short edge;
};
vector<int> X;
vector<int> Y;
map<int,parent> memo;
int NEXT_FREE_INDEX=1;
int limit;
void createTree(int i,int lv,int sum,int unused)
{
if(lv==limit-1){ //Last level of switches
if(unused==1)
X.push_back(-1);
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(-1);
Y.push_back(-NEXT_FREE_INDEX);
NEXT_FREE_INDEX++;
createTree(NEXT_FREE_INDEX-1,lv+1,sum+(1<<lv),unused-child_size);
}
else{
X.push_back(-NEXT_FREE_INDEX);
NEXT_FREE_INDEX++;
Y.push_back(0);
createTree(NEXT_FREE_INDEX-1,lv+1,sum,unused);
Y[i-1]=-NEXT_FREE_INDEX;
NEXT_FREE_INDEX++;
createTree(NEXT_FREE_INDEX-1,lv+1,sum+(1<<lv),0);
}
}
}
void create_circuit(int m, vector<int> A) {
A.push_back(0);
int n=A.size();
vector<int> C(m+1);
for(int i=0;i<=m;i++){
C[i]=-1;
}
int LOG=0;
while((1<<LOG)<n){
LOG++;
}
NEXT_FREE_INDEX++;
limit=LOG;
createTree(1,0,0,(1<<LOG)-n);
/*for(int i=0;i<n;i++){
cout<<X[i]<<" "<<Y[i]<<endl;
}*/
int j=0;
map<int,parent>::iterator it;
for(it=memo.begin();it!=memo.end();it++){
pair<int,parent> x=(*it);
int p=x.second.p;
int edge=x.second.edge;
if(edge==0) X[p-1]=A[j];
else Y[p-1]=A[j];
j++;
}
memo.clear();
/*for(int i=0;i<n;i++){
cout<<X[i]<<" "<<Y[i]<<endl;
}*/
answer(C, X, Y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
57 ms |
6348 KB |
Output is correct |
3 |
Correct |
68 ms |
6536 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
15 ms |
1356 KB |
Output is correct |
6 |
Correct |
103 ms |
9628 KB |
Output is correct |
7 |
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 |
57 ms |
6348 KB |
Output is correct |
3 |
Correct |
68 ms |
6536 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
15 ms |
1356 KB |
Output is correct |
6 |
Correct |
103 ms |
9628 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
142 ms |
12296 KB |
Output is correct |
9 |
Correct |
130 ms |
12492 KB |
Output is correct |
10 |
Correct |
209 ms |
18452 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
57 ms |
6348 KB |
Output is correct |
3 |
Correct |
68 ms |
6536 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
15 ms |
1356 KB |
Output is correct |
6 |
Correct |
103 ms |
9628 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
142 ms |
12296 KB |
Output is correct |
9 |
Correct |
130 ms |
12492 KB |
Output is correct |
10 |
Correct |
209 ms |
18452 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
2 ms |
204 KB |
Output is correct |
14 |
Correct |
194 ms |
18324 KB |
Output is correct |
15 |
Correct |
117 ms |
12060 KB |
Output is correct |
16 |
Correct |
244 ms |
18068 KB |
Output is correct |
17 |
Correct |
2 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 |
186 ms |
18356 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 |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
110 ms |
11684 KB |
Output is correct |
3 |
Correct |
117 ms |
11552 KB |
Output is correct |
4 |
Correct |
197 ms |
17008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
110 ms |
11684 KB |
Output is correct |
3 |
Correct |
117 ms |
11552 KB |
Output is correct |
4 |
Correct |
197 ms |
17008 KB |
Output is correct |
5 |
Correct |
196 ms |
18032 KB |
Output is correct |
6 |
Correct |
218 ms |
17908 KB |
Output is correct |
7 |
Correct |
211 ms |
17908 KB |
Output is correct |
8 |
Correct |
207 ms |
17680 KB |
Output is correct |
9 |
Correct |
116 ms |
11592 KB |
Output is correct |
10 |
Correct |
208 ms |
17680 KB |
Output is correct |
11 |
Correct |
222 ms |
17332 KB |
Output is correct |
12 |
Correct |
114 ms |
11572 KB |
Output is correct |
13 |
Correct |
114 ms |
11812 KB |
Output is correct |
14 |
Correct |
117 ms |
11860 KB |
Output is correct |
15 |
Correct |
120 ms |
11912 KB |
Output is correct |
16 |
Correct |
4 ms |
588 KB |
Output is correct |
17 |
Correct |
123 ms |
11416 KB |
Output is correct |
18 |
Correct |
137 ms |
11524 KB |
Output is correct |
19 |
Correct |
119 ms |
11548 KB |
Output is correct |
20 |
Correct |
230 ms |
17604 KB |
Output is correct |
21 |
Correct |
244 ms |
17344 KB |
Output is correct |
22 |
Correct |
186 ms |
17428 KB |
Output is correct |