#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
void create_circuit(int m, vector<int> a) {
int n = a.size();
int len = 0;
int cnt = -2;
while((1<<len) < n + 1)len++;
vector <int> c(m + 1);
vector <int> x((1<<len) - 1);
vector <int> y((1<<len) - 1);
vector <int> x2;
vector <int> y2;
vector <array<int,3>> ord;
for(int i = 0;i < m + 1;i++){
c[i] = -1;
}
auto dfs = [&](auto self,int node,int d) -> void {
if(d == len - 1){
x[-node - 1] = -1;
y[-node - 1] = -1;
}else{
x[-node - 1] = cnt--;
self(self,cnt + 1,d + 1);
y[-node - 1] = cnt--;
self(self,cnt + 1,d + 1);
}
};
int cnt2 = 0,last = 0;
auto dfs2 = [&](auto self,int node,int d) -> void {
if(d == len - 1){
int nr = 0;
for(int j = 0;j < len;j++){
if(cnt2>>j&1){
nr|=(1<<(len - j - 1));
}
}
if(cnt2 + n >= (1<<len) - 1 && cnt2 != (1<<len) - 1)ord.push_back({nr,node,0});
cnt2++;
if(cnt2 + n >= (1<<len) - 1 && cnt2 != (1<<len) - 1)ord.push_back({nr + (1<<len),node,1});
cnt2++;
last = node;
}else{
self(self,-x[node] - 1,d + 1);
self(self,-y[node] - 1,d + 1);
}
};
auto dfs3 = [&](auto self,int node,int d) -> int {
if(d == len - 1){
if(x[node] == -1 && y[node] == -1){
return -1;
}else{
x2.push_back(x[node]);
y2.push_back(y[node]);
return x2.size() - 1;
}
}else{
if(node == 0){
x2.push_back(0);
y2.push_back(0);
}
int l = self(self,-x[node] - 1,d + 1);
int r = self(self,-y[node] - 1,d + 1);
if(l == -1 && r == -1)return -1;
else{
if(node == 0){
if(l != -1){
x2[0] = -l - 1;
}else x2[0] = -1;
if(r != -1){
y2[0] = -r - 1;
}else y2[0] = -1;
}else{
if(l != -1){
x2.push_back(-l - 1);
}else x2.push_back(-1);
if(r != -1){
y2.push_back(-r - 1);
}else y2.push_back(-1);
}
return x2.size() - 1;
}
}
};
dfs(dfs,-1,0);
dfs2(dfs2,0,0);
int cnt3 = 0;
sort(ord.begin(),ord.end());
for(auto i:ord){
//cout<<i[0]<<' '<<i[1]<<' '<<i[2]<<'\n';
if(i[2] == 0){
x[i[1]] = a[cnt3];
}else{
y[i[1]] = a[cnt3];
}
cnt3++;
}
y[last] = 0;
/*for(int i = 0;i < (1<<len) - 1;i++){
cout<<x[i]<<' '<<y[i]<<'\n';
}*/
dfs3(dfs3,0,0);
/*for(int i = 0;i < x2.size();i++){
cout<<x2[i]<<' '<<y2[i]<<'\n';
}*/
return answer(c,x2,y2);
}
/**
7 7
1 2 3 4 5 6 7
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
32 ms |
6048 KB |
Output is correct |
3 |
Correct |
31 ms |
5836 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Correct |
44 ms |
7880 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
32 ms |
6048 KB |
Output is correct |
3 |
Correct |
31 ms |
5836 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Correct |
44 ms |
7880 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
57 ms |
9628 KB |
Output is correct |
9 |
Correct |
59 ms |
11724 KB |
Output is correct |
10 |
Correct |
82 ms |
13764 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
32 ms |
6048 KB |
Output is correct |
3 |
Correct |
31 ms |
5836 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
7 ms |
1372 KB |
Output is correct |
6 |
Correct |
44 ms |
7880 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
57 ms |
9628 KB |
Output is correct |
9 |
Correct |
59 ms |
11724 KB |
Output is correct |
10 |
Correct |
82 ms |
13764 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
85 ms |
13272 KB |
Output is correct |
15 |
Correct |
55 ms |
9564 KB |
Output is correct |
16 |
Correct |
79 ms |
13244 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
86 ms |
13700 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
51 ms |
8140 KB |
Output is correct |
3 |
Correct |
62 ms |
9160 KB |
Output is correct |
4 |
Correct |
72 ms |
12228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
51 ms |
8140 KB |
Output is correct |
3 |
Correct |
62 ms |
9160 KB |
Output is correct |
4 |
Correct |
72 ms |
12228 KB |
Output is correct |
5 |
Correct |
84 ms |
11812 KB |
Output is correct |
6 |
Correct |
81 ms |
12448 KB |
Output is correct |
7 |
Correct |
89 ms |
11704 KB |
Output is correct |
8 |
Correct |
75 ms |
11572 KB |
Output is correct |
9 |
Correct |
53 ms |
9024 KB |
Output is correct |
10 |
Correct |
84 ms |
12304 KB |
Output is correct |
11 |
Correct |
80 ms |
12248 KB |
Output is correct |
12 |
Correct |
57 ms |
9208 KB |
Output is correct |
13 |
Correct |
61 ms |
8076 KB |
Output is correct |
14 |
Correct |
58 ms |
8352 KB |
Output is correct |
15 |
Correct |
56 ms |
9636 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
51 ms |
7252 KB |
Output is correct |
18 |
Correct |
55 ms |
8012 KB |
Output is correct |
19 |
Correct |
55 ms |
8284 KB |
Output is correct |
20 |
Correct |
87 ms |
11716 KB |
Output is correct |
21 |
Correct |
83 ms |
12076 KB |
Output is correct |
22 |
Correct |
74 ms |
11676 KB |
Output is correct |