#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)ord.push_back({nr,node,0});
cnt2++;
if(cnt2 < n)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){
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);
}
/**
5 4
1 2 3 1
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
50 ms |
8024 KB |
Output is correct |
3 |
Partially correct |
63 ms |
8260 KB |
Output is partially correct |
4 |
Partially correct |
89 ms |
11940 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
0 ms |
348 KB |
Output is partially correct |
2 |
Correct |
50 ms |
8024 KB |
Output is correct |
3 |
Partially correct |
63 ms |
8260 KB |
Output is partially correct |
4 |
Partially correct |
89 ms |
11940 KB |
Output is partially correct |
5 |
Partially correct |
80 ms |
11632 KB |
Output is partially correct |
6 |
Partially correct |
78 ms |
12228 KB |
Output is partially correct |
7 |
Partially correct |
83 ms |
11880 KB |
Output is partially correct |
8 |
Partially correct |
75 ms |
11720 KB |
Output is partially correct |
9 |
Partially correct |
51 ms |
9408 KB |
Output is partially correct |
10 |
Partially correct |
78 ms |
11676 KB |
Output is partially correct |
11 |
Partially correct |
76 ms |
12372 KB |
Output is partially correct |
12 |
Partially correct |
52 ms |
9664 KB |
Output is partially correct |
13 |
Correct |
51 ms |
8140 KB |
Output is correct |
14 |
Partially correct |
54 ms |
8392 KB |
Output is partially correct |
15 |
Partially correct |
55 ms |
8388 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
604 KB |
Output is partially correct |
17 |
Correct |
57 ms |
7256 KB |
Output is correct |
18 |
Correct |
50 ms |
8140 KB |
Output is correct |
19 |
Partially correct |
54 ms |
8504 KB |
Output is partially correct |
20 |
Partially correct |
78 ms |
11664 KB |
Output is partially correct |
21 |
Partially correct |
74 ms |
11464 KB |
Output is partially correct |
22 |
Partially correct |
76 ms |
11572 KB |
Output is partially correct |