#include "parks.h"
#include <bits/stdc++.h>
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
struct DSU{
vector<int> bo,ss;
void init(int x){
bo.resize(x);
ss.resize(x,1);
iota(bo.begin(),bo.end(),0);
}
int find(int x){
return bo[x]==x?x:bo[x]=find(bo[x]);
}
int merge(int x,int y){
x=find(x);
y=find(y);
if(x==y){
return 0;
}
bo[x]=y;
ss[y]+=ss[x];
return 1;
}
}dsu;
vector<int> au,av,aa,ab;
void ag(int a,int b,int c,int d){
au.push_back(a);
av.push_back(b);
aa.push_back(c);
ab.push_back(d);
}
int construct_roads(vector<int> x, vector<int> y) {
if (x.size() == 1) {
build({}, {}, {}, {});
return 1;
}
map<pair<int,int>,int> m;
int n=x.size();
for(int i=0;i<n;i++){
m[{x[i],y[i]}]=i+1;
}
dsu.init(n);
vector<int> up(n,-1),l(n,-1),r(n,-1);
vector<pair<int,int> > lb;
for(int p=0;p<n;p++){
if(m.find({x[p],y[p]+2})!=m.end()){
int a=m[{x[p],y[p]+2}]-1;
dsu.merge(a,p);
if(x[p]==2){
ag(a,p,1,y[p]+1);
}
else if(x[p]==6){
ag(a,p,7,y[p]+1);
}
else{
up[a]=p;
}
}
}
for(int p=0;p<n;p++){
if(x[p]==4){
lb.push_back({y[p],p});
if(m.find({2,y[p]})!=m.end()){
int a=m[{2,y[p]}]-1;
if(dsu.merge(a,p)){
l[p]=a;
}
}
if(m.find({6,y[p]})!=m.end()){
int a=m[{6,y[p]}]-1;
if(dsu.merge(a,p)){
r[p]=a;
}
}
}
}
if(dsu.ss[dsu.find(0)]!=n){
return 0;
}
sort(lb.begin(),lb.end());
int flag=0;
int lst=0;
for(auto h:lb){
int i=h.sc;
if(lst!=h.fs-2){
flag=0;
}
if(flag){
if(up[i]>=0){
ag(up[i],i,3,h.fs-1);
}
flag=0;
lst=h.fs;
continue;
}
if(up[i]>=0){
if(l[i]>=0 && r[i]>=0){
ag(l[i],i,3,h.fs-1);
ag(up[i],i,5,h.fs-1);
ag(r[i],i,5,h.fs+1);
flag=1;
}
else if(l[i]>=0){
ag(l[i],i,3,h.fs-1);
ag(up[i],i,5,h.fs-1);
}
else if(r[i]>=0){
ag(r[i],i,5,h.fs-1);
ag(up[i],i,3,h.fs-1);
}
else{
ag(up[i],i,3,h.fs-1);
}
}
else{
if(l[i]>=0){
ag(l[i],i,3,h.fs-1);
}
if(r[i]>=0){
ag(r[i],i,5,h.fs-1);
}
}
lst=h.fs;
}
build(au,av,aa,ab);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
105 ms |
15124 KB |
Output is correct |
10 |
Correct |
7 ms |
1988 KB |
Output is correct |
11 |
Correct |
39 ms |
8512 KB |
Output is correct |
12 |
Correct |
13 ms |
2772 KB |
Output is correct |
13 |
Correct |
22 ms |
5756 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
108 ms |
15108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
105 ms |
15124 KB |
Output is correct |
10 |
Correct |
7 ms |
1988 KB |
Output is correct |
11 |
Correct |
39 ms |
8512 KB |
Output is correct |
12 |
Correct |
13 ms |
2772 KB |
Output is correct |
13 |
Correct |
22 ms |
5756 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
108 ms |
15108 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
224 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
372 ms |
30448 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
788 KB |
Output is correct |
28 |
Correct |
107 ms |
12756 KB |
Output is correct |
29 |
Correct |
173 ms |
18672 KB |
Output is correct |
30 |
Correct |
257 ms |
24612 KB |
Output is correct |
31 |
Correct |
338 ms |
30560 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
268 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
596 KB |
Output is correct |
45 |
Correct |
137 ms |
15608 KB |
Output is correct |
46 |
Correct |
253 ms |
22772 KB |
Output is correct |
47 |
Correct |
239 ms |
22760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
105 ms |
15124 KB |
Output is correct |
10 |
Correct |
7 ms |
1988 KB |
Output is correct |
11 |
Correct |
39 ms |
8512 KB |
Output is correct |
12 |
Correct |
13 ms |
2772 KB |
Output is correct |
13 |
Correct |
22 ms |
5756 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
108 ms |
15108 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
224 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
372 ms |
30448 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
788 KB |
Output is correct |
28 |
Correct |
107 ms |
12756 KB |
Output is correct |
29 |
Correct |
173 ms |
18672 KB |
Output is correct |
30 |
Correct |
257 ms |
24612 KB |
Output is correct |
31 |
Correct |
338 ms |
30560 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
268 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
596 KB |
Output is correct |
45 |
Correct |
137 ms |
15608 KB |
Output is correct |
46 |
Correct |
253 ms |
22772 KB |
Output is correct |
47 |
Correct |
239 ms |
22760 KB |
Output is correct |
48 |
Correct |
1 ms |
296 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 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 |
Correct |
1 ms |
304 KB |
Output is correct |
54 |
Correct |
1 ms |
296 KB |
Output is correct |
55 |
Correct |
479 ms |
30312 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
2 ms |
596 KB |
Output is correct |
58 |
Correct |
7 ms |
1336 KB |
Output is correct |
59 |
Correct |
8 ms |
1484 KB |
Output is correct |
60 |
Correct |
160 ms |
15540 KB |
Output is correct |
61 |
Correct |
213 ms |
20664 KB |
Output is correct |
62 |
Correct |
276 ms |
25116 KB |
Output is correct |
63 |
Correct |
349 ms |
30344 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
1 ms |
212 KB |
Output is correct |
67 |
Correct |
281 ms |
29808 KB |
Output is correct |
68 |
Correct |
282 ms |
29804 KB |
Output is correct |
69 |
Correct |
279 ms |
29612 KB |
Output is correct |
70 |
Correct |
3 ms |
724 KB |
Output is correct |
71 |
Correct |
5 ms |
1208 KB |
Output is correct |
72 |
Correct |
123 ms |
15368 KB |
Output is correct |
73 |
Correct |
245 ms |
22928 KB |
Output is correct |
74 |
Correct |
389 ms |
30396 KB |
Output is correct |
75 |
Correct |
424 ms |
30608 KB |
Output is correct |
76 |
Correct |
321 ms |
29976 KB |
Output is correct |
77 |
Correct |
3 ms |
852 KB |
Output is correct |
78 |
Correct |
6 ms |
1364 KB |
Output is correct |
79 |
Correct |
145 ms |
15544 KB |
Output is correct |
80 |
Correct |
258 ms |
22996 KB |
Output is correct |
81 |
Correct |
328 ms |
30340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
105 ms |
15124 KB |
Output is correct |
10 |
Correct |
7 ms |
1988 KB |
Output is correct |
11 |
Correct |
39 ms |
8512 KB |
Output is correct |
12 |
Correct |
13 ms |
2772 KB |
Output is correct |
13 |
Correct |
22 ms |
5756 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
108 ms |
15108 KB |
Output is correct |
17 |
Incorrect |
1 ms |
296 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
105 ms |
15124 KB |
Output is correct |
10 |
Correct |
7 ms |
1988 KB |
Output is correct |
11 |
Correct |
39 ms |
8512 KB |
Output is correct |
12 |
Correct |
13 ms |
2772 KB |
Output is correct |
13 |
Correct |
22 ms |
5756 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
108 ms |
15108 KB |
Output is correct |
17 |
Incorrect |
211 ms |
21036 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
105 ms |
15124 KB |
Output is correct |
10 |
Correct |
7 ms |
1988 KB |
Output is correct |
11 |
Correct |
39 ms |
8512 KB |
Output is correct |
12 |
Correct |
13 ms |
2772 KB |
Output is correct |
13 |
Correct |
22 ms |
5756 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
108 ms |
15108 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
1 ms |
224 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
372 ms |
30448 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
596 KB |
Output is correct |
27 |
Correct |
3 ms |
788 KB |
Output is correct |
28 |
Correct |
107 ms |
12756 KB |
Output is correct |
29 |
Correct |
173 ms |
18672 KB |
Output is correct |
30 |
Correct |
257 ms |
24612 KB |
Output is correct |
31 |
Correct |
338 ms |
30560 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
268 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
2 ms |
596 KB |
Output is correct |
45 |
Correct |
137 ms |
15608 KB |
Output is correct |
46 |
Correct |
253 ms |
22772 KB |
Output is correct |
47 |
Correct |
239 ms |
22760 KB |
Output is correct |
48 |
Correct |
1 ms |
296 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 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 |
Correct |
1 ms |
304 KB |
Output is correct |
54 |
Correct |
1 ms |
296 KB |
Output is correct |
55 |
Correct |
479 ms |
30312 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
2 ms |
596 KB |
Output is correct |
58 |
Correct |
7 ms |
1336 KB |
Output is correct |
59 |
Correct |
8 ms |
1484 KB |
Output is correct |
60 |
Correct |
160 ms |
15540 KB |
Output is correct |
61 |
Correct |
213 ms |
20664 KB |
Output is correct |
62 |
Correct |
276 ms |
25116 KB |
Output is correct |
63 |
Correct |
349 ms |
30344 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
1 ms |
212 KB |
Output is correct |
67 |
Correct |
281 ms |
29808 KB |
Output is correct |
68 |
Correct |
282 ms |
29804 KB |
Output is correct |
69 |
Correct |
279 ms |
29612 KB |
Output is correct |
70 |
Correct |
3 ms |
724 KB |
Output is correct |
71 |
Correct |
5 ms |
1208 KB |
Output is correct |
72 |
Correct |
123 ms |
15368 KB |
Output is correct |
73 |
Correct |
245 ms |
22928 KB |
Output is correct |
74 |
Correct |
389 ms |
30396 KB |
Output is correct |
75 |
Correct |
424 ms |
30608 KB |
Output is correct |
76 |
Correct |
321 ms |
29976 KB |
Output is correct |
77 |
Correct |
3 ms |
852 KB |
Output is correct |
78 |
Correct |
6 ms |
1364 KB |
Output is correct |
79 |
Correct |
145 ms |
15544 KB |
Output is correct |
80 |
Correct |
258 ms |
22996 KB |
Output is correct |
81 |
Correct |
328 ms |
30340 KB |
Output is correct |
82 |
Incorrect |
1 ms |
296 KB |
Solution announced impossible, but it is possible. |
83 |
Halted |
0 ms |
0 KB |
- |