#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
struct edges{
int x,y,x1,y1;
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
map<pair<int,int>,bool>mp,got,have;
map<pair<int,int>,int>index;
int n = (int)x.size();
for (int i = 0;i<n;++i){
mp[{x[i],y[i]}] = true;
got[{x[i],y[i]}] = false;
index[{x[i],y[i]}] = i;
}
auto comp = [&](int a,int b,int c,int d){
if (a<c){
return (edges){a,b,c,d};
}
else if (c < a){
return (edges){c,d,a,b};
}
else if ( b < d){
return (edges){a,b,c,d};
}
return (edges){c,d,a,b};
};
vector<edges>ans;
vector<int>dx = {2,0,-2,0};
vector<int>dy = {0,2,0,-2};
function<void(int,int)> dfs = [&](int u,int v){
got[{u,v}] = true;
for (int i = 0;i<4;++i){
int xx = u + dx[i];
int yy = v + dy[i];
if (mp[{xx,yy}] && !got[{xx,yy}]){
ans.push_back(comp(u,v,xx,yy));
dfs(xx,yy);
}
}
};
bool ok = true;
dfs(x[0],y[0]);
for (int i = 0;i<n;++i){
if (!got[{x[i],y[i]}]){
ok=false;
break;
}
}
if (!ok){
return 0;
}
sort(ans.begin(),ans.end(),[&](auto xx,auto yy){
return xx.x<yy.x;
});
vector<int>u,v,a,b;
for (auto z:ans){
int xx = z.x1;
int yy = z.y1;
u.push_back(index[{z.x,z.y}]);
v.push_back(index[{z.x1,z.y1}]);
if (z.x == z.x1){
if (!have[{xx - 1,yy - 1}]){
have[{xx - 1,yy - 1}] = true;
a.push_back(xx - 1 );
b.push_back(yy- 1);
}
else{
a.push_back(xx + 1);
b.push_back(yy - 1);
have[{xx+1,yy - 1}] = true;
}
}
else {
if (!have[{xx - 1,yy + 1}]){
have[{xx - 1,yy + 1}] = true;
a.push_back(xx-1);
b.push_back(yy+ 1);
}
else{
a.push_back(xx - 1);
b.push_back(yy - 1);
have[{xx - 1,yy - 1}] = true;
}
}
}
build(u,v,a,b);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 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 |
9 |
Correct |
447 ms |
57288 KB |
Output is correct |
10 |
Correct |
24 ms |
6108 KB |
Output is correct |
11 |
Correct |
169 ms |
31456 KB |
Output is correct |
12 |
Correct |
50 ms |
8944 KB |
Output is correct |
13 |
Correct |
82 ms |
17300 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
412 ms |
52196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 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 |
9 |
Correct |
447 ms |
57288 KB |
Output is correct |
10 |
Correct |
24 ms |
6108 KB |
Output is correct |
11 |
Correct |
169 ms |
31456 KB |
Output is correct |
12 |
Correct |
50 ms |
8944 KB |
Output is correct |
13 |
Correct |
82 ms |
17300 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
412 ms |
52196 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1029 ms |
103884 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
4 ms |
852 KB |
Output is correct |
26 |
Correct |
4 ms |
1108 KB |
Output is correct |
27 |
Correct |
6 ms |
1236 KB |
Output is correct |
28 |
Correct |
347 ms |
42036 KB |
Output is correct |
29 |
Correct |
577 ms |
59356 KB |
Output is correct |
30 |
Correct |
778 ms |
82276 KB |
Output is correct |
31 |
Correct |
997 ms |
104428 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
300 KB |
Output is correct |
34 |
Correct |
1 ms |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
300 KB |
Output is correct |
42 |
Correct |
1 ms |
296 KB |
Output is correct |
43 |
Correct |
3 ms |
856 KB |
Output is correct |
44 |
Correct |
3 ms |
980 KB |
Output is correct |
45 |
Correct |
464 ms |
50204 KB |
Output is correct |
46 |
Correct |
694 ms |
73612 KB |
Output is correct |
47 |
Correct |
705 ms |
72848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 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 |
9 |
Correct |
447 ms |
57288 KB |
Output is correct |
10 |
Correct |
24 ms |
6108 KB |
Output is correct |
11 |
Correct |
169 ms |
31456 KB |
Output is correct |
12 |
Correct |
50 ms |
8944 KB |
Output is correct |
13 |
Correct |
82 ms |
17300 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
412 ms |
52196 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1029 ms |
103884 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
4 ms |
852 KB |
Output is correct |
26 |
Correct |
4 ms |
1108 KB |
Output is correct |
27 |
Correct |
6 ms |
1236 KB |
Output is correct |
28 |
Correct |
347 ms |
42036 KB |
Output is correct |
29 |
Correct |
577 ms |
59356 KB |
Output is correct |
30 |
Correct |
778 ms |
82276 KB |
Output is correct |
31 |
Correct |
997 ms |
104428 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
300 KB |
Output is correct |
34 |
Correct |
1 ms |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
300 KB |
Output is correct |
42 |
Correct |
1 ms |
296 KB |
Output is correct |
43 |
Correct |
3 ms |
856 KB |
Output is correct |
44 |
Correct |
3 ms |
980 KB |
Output is correct |
45 |
Correct |
464 ms |
50204 KB |
Output is correct |
46 |
Correct |
694 ms |
73612 KB |
Output is correct |
47 |
Correct |
705 ms |
72848 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
300 KB |
Output is correct |
53 |
Incorrect |
1 ms |
212 KB |
Tree @(5, 5) appears more than once: for edges on positions 2 and 4 |
54 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 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 |
9 |
Correct |
447 ms |
57288 KB |
Output is correct |
10 |
Correct |
24 ms |
6108 KB |
Output is correct |
11 |
Correct |
169 ms |
31456 KB |
Output is correct |
12 |
Correct |
50 ms |
8944 KB |
Output is correct |
13 |
Correct |
82 ms |
17300 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
412 ms |
52196 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
976 ms |
103704 KB |
Output is correct |
21 |
Correct |
978 ms |
98660 KB |
Output is correct |
22 |
Correct |
953 ms |
95896 KB |
Output is correct |
23 |
Correct |
837 ms |
91436 KB |
Output is correct |
24 |
Correct |
443 ms |
40920 KB |
Output is correct |
25 |
Correct |
436 ms |
41100 KB |
Output is correct |
26 |
Correct |
449 ms |
41132 KB |
Output is correct |
27 |
Incorrect |
886 ms |
79028 KB |
Tree @(7, 3) appears more than once: for edges on positions 658 and 659 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 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 |
9 |
Correct |
447 ms |
57288 KB |
Output is correct |
10 |
Correct |
24 ms |
6108 KB |
Output is correct |
11 |
Correct |
169 ms |
31456 KB |
Output is correct |
12 |
Correct |
50 ms |
8944 KB |
Output is correct |
13 |
Correct |
82 ms |
17300 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
412 ms |
52196 KB |
Output is correct |
17 |
Correct |
1016 ms |
116396 KB |
Output is correct |
18 |
Correct |
974 ms |
106376 KB |
Output is correct |
19 |
Incorrect |
958 ms |
103816 KB |
Tree @(50011, 99993) appears more than once: for edges on positions 100013 and 100014 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
212 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 |
9 |
Correct |
447 ms |
57288 KB |
Output is correct |
10 |
Correct |
24 ms |
6108 KB |
Output is correct |
11 |
Correct |
169 ms |
31456 KB |
Output is correct |
12 |
Correct |
50 ms |
8944 KB |
Output is correct |
13 |
Correct |
82 ms |
17300 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
2 ms |
724 KB |
Output is correct |
16 |
Correct |
412 ms |
52196 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1029 ms |
103884 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
4 ms |
852 KB |
Output is correct |
26 |
Correct |
4 ms |
1108 KB |
Output is correct |
27 |
Correct |
6 ms |
1236 KB |
Output is correct |
28 |
Correct |
347 ms |
42036 KB |
Output is correct |
29 |
Correct |
577 ms |
59356 KB |
Output is correct |
30 |
Correct |
778 ms |
82276 KB |
Output is correct |
31 |
Correct |
997 ms |
104428 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
300 KB |
Output is correct |
34 |
Correct |
1 ms |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
300 KB |
Output is correct |
42 |
Correct |
1 ms |
296 KB |
Output is correct |
43 |
Correct |
3 ms |
856 KB |
Output is correct |
44 |
Correct |
3 ms |
980 KB |
Output is correct |
45 |
Correct |
464 ms |
50204 KB |
Output is correct |
46 |
Correct |
694 ms |
73612 KB |
Output is correct |
47 |
Correct |
705 ms |
72848 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
300 KB |
Output is correct |
53 |
Incorrect |
1 ms |
212 KB |
Tree @(5, 5) appears more than once: for edges on positions 2 and 4 |
54 |
Halted |
0 ms |
0 KB |
- |