#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
int n,order[200001],p[200001],cnt;
map <int, int> mp[300001];
vector <int> px,py;
int f(int i){
return (p[i]==i?i:p[i]=f(p[i]));
}
bool unite(int i, int j){
i=f(i);
j=f(j);
if (i==j)
return false;
p[j]=i;
return true;
}
int construct_roads(vector <int> x, vector <int> y){
vector <int32_t> u,v,a,b;
n=x.size();
for (int i=0;i<n;i++)
mp[x[i]][y[i]]=i;
iota(order,order+n,0);
px=x,py=y;
sort(order,order+n,[](int i, int j){return make_pair(px[i],py[i])<make_pair(px[j],py[j]);});
for (int i=0;i<n;i++){
if (mp[x[i]-2].count(y[i])){
int X=x[i]-1,Y=(x[i]%4?(y[i]+3)/4*4-1:y[i]/4*4+1);
if (!mp[X].count(Y)){
u.push_back(i);
v.push_back(mp[x[i]-2][y[i]]);
a.push_back(X);
b.push_back(Y);
mp[X][Y]=1;
}
}
if (mp[x[i]].count(y[i]-2)){
int X=(y[i]%4?x[i]/4*4+1:(x[i]+3)/4*4-1),Y=y[i]-1;
if (!mp[X].count(Y)){
u.push_back(i);
v.push_back(mp[x[i]][y[i]-2]);
a.push_back(X);
b.push_back(Y);
mp[X][Y]=1;
}
}
}
iota(p,p+n,0);
for (int i=0;i<u.size();i++)
cnt+=unite(u[i],v[i]);
if (cnt<n-1)
return 0;
build(u,v,a,b);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i=0;i<u.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
172 ms |
31856 KB |
Output is correct |
10 |
Correct |
11 ms |
16732 KB |
Output is correct |
11 |
Correct |
56 ms |
24004 KB |
Output is correct |
12 |
Correct |
18 ms |
17912 KB |
Output is correct |
13 |
Correct |
31 ms |
21036 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
4 ms |
15192 KB |
Output is correct |
16 |
Correct |
151 ms |
31732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
172 ms |
31856 KB |
Output is correct |
10 |
Correct |
11 ms |
16732 KB |
Output is correct |
11 |
Correct |
56 ms |
24004 KB |
Output is correct |
12 |
Correct |
18 ms |
17912 KB |
Output is correct |
13 |
Correct |
31 ms |
21036 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
4 ms |
15192 KB |
Output is correct |
16 |
Correct |
151 ms |
31732 KB |
Output is correct |
17 |
Correct |
3 ms |
14936 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14940 KB |
Output is correct |
20 |
Correct |
3 ms |
14940 KB |
Output is correct |
21 |
Correct |
4 ms |
14936 KB |
Output is correct |
22 |
Correct |
3 ms |
14940 KB |
Output is correct |
23 |
Correct |
569 ms |
48888 KB |
Output is correct |
24 |
Correct |
3 ms |
14936 KB |
Output is correct |
25 |
Correct |
4 ms |
15196 KB |
Output is correct |
26 |
Correct |
6 ms |
15196 KB |
Output is correct |
27 |
Correct |
7 ms |
15452 KB |
Output is correct |
28 |
Correct |
141 ms |
28280 KB |
Output is correct |
29 |
Correct |
265 ms |
35200 KB |
Output is correct |
30 |
Correct |
334 ms |
42064 KB |
Output is correct |
31 |
Correct |
434 ms |
48864 KB |
Output is correct |
32 |
Correct |
3 ms |
14940 KB |
Output is correct |
33 |
Correct |
3 ms |
14940 KB |
Output is correct |
34 |
Correct |
3 ms |
14936 KB |
Output is correct |
35 |
Correct |
3 ms |
14936 KB |
Output is correct |
36 |
Correct |
3 ms |
14940 KB |
Output is correct |
37 |
Correct |
3 ms |
14936 KB |
Output is correct |
38 |
Correct |
3 ms |
14940 KB |
Output is correct |
39 |
Correct |
3 ms |
14940 KB |
Output is correct |
40 |
Correct |
3 ms |
14940 KB |
Output is correct |
41 |
Correct |
3 ms |
14940 KB |
Output is correct |
42 |
Correct |
3 ms |
14940 KB |
Output is correct |
43 |
Correct |
4 ms |
15196 KB |
Output is correct |
44 |
Correct |
5 ms |
15196 KB |
Output is correct |
45 |
Correct |
165 ms |
31684 KB |
Output is correct |
46 |
Correct |
287 ms |
39404 KB |
Output is correct |
47 |
Correct |
263 ms |
39336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
172 ms |
31856 KB |
Output is correct |
10 |
Correct |
11 ms |
16732 KB |
Output is correct |
11 |
Correct |
56 ms |
24004 KB |
Output is correct |
12 |
Correct |
18 ms |
17912 KB |
Output is correct |
13 |
Correct |
31 ms |
21036 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
4 ms |
15192 KB |
Output is correct |
16 |
Correct |
151 ms |
31732 KB |
Output is correct |
17 |
Correct |
3 ms |
14936 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14940 KB |
Output is correct |
20 |
Correct |
3 ms |
14940 KB |
Output is correct |
21 |
Correct |
4 ms |
14936 KB |
Output is correct |
22 |
Correct |
3 ms |
14940 KB |
Output is correct |
23 |
Correct |
569 ms |
48888 KB |
Output is correct |
24 |
Correct |
3 ms |
14936 KB |
Output is correct |
25 |
Correct |
4 ms |
15196 KB |
Output is correct |
26 |
Correct |
6 ms |
15196 KB |
Output is correct |
27 |
Correct |
7 ms |
15452 KB |
Output is correct |
28 |
Correct |
141 ms |
28280 KB |
Output is correct |
29 |
Correct |
265 ms |
35200 KB |
Output is correct |
30 |
Correct |
334 ms |
42064 KB |
Output is correct |
31 |
Correct |
434 ms |
48864 KB |
Output is correct |
32 |
Correct |
3 ms |
14940 KB |
Output is correct |
33 |
Correct |
3 ms |
14940 KB |
Output is correct |
34 |
Correct |
3 ms |
14936 KB |
Output is correct |
35 |
Correct |
3 ms |
14936 KB |
Output is correct |
36 |
Correct |
3 ms |
14940 KB |
Output is correct |
37 |
Correct |
3 ms |
14936 KB |
Output is correct |
38 |
Correct |
3 ms |
14940 KB |
Output is correct |
39 |
Correct |
3 ms |
14940 KB |
Output is correct |
40 |
Correct |
3 ms |
14940 KB |
Output is correct |
41 |
Correct |
3 ms |
14940 KB |
Output is correct |
42 |
Correct |
3 ms |
14940 KB |
Output is correct |
43 |
Correct |
4 ms |
15196 KB |
Output is correct |
44 |
Correct |
5 ms |
15196 KB |
Output is correct |
45 |
Correct |
165 ms |
31684 KB |
Output is correct |
46 |
Correct |
287 ms |
39404 KB |
Output is correct |
47 |
Correct |
263 ms |
39336 KB |
Output is correct |
48 |
Correct |
3 ms |
14936 KB |
Output is correct |
49 |
Correct |
3 ms |
15192 KB |
Output is correct |
50 |
Correct |
3 ms |
14940 KB |
Output is correct |
51 |
Correct |
4 ms |
14940 KB |
Output is correct |
52 |
Correct |
3 ms |
14940 KB |
Output is correct |
53 |
Correct |
3 ms |
14940 KB |
Output is correct |
54 |
Correct |
3 ms |
14940 KB |
Output is correct |
55 |
Incorrect |
439 ms |
42636 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
172 ms |
31856 KB |
Output is correct |
10 |
Correct |
11 ms |
16732 KB |
Output is correct |
11 |
Correct |
56 ms |
24004 KB |
Output is correct |
12 |
Correct |
18 ms |
17912 KB |
Output is correct |
13 |
Correct |
31 ms |
21036 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
4 ms |
15192 KB |
Output is correct |
16 |
Correct |
151 ms |
31732 KB |
Output is correct |
17 |
Correct |
3 ms |
14940 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14936 KB |
Output is correct |
20 |
Correct |
219 ms |
48808 KB |
Output is correct |
21 |
Correct |
273 ms |
48972 KB |
Output is correct |
22 |
Correct |
270 ms |
48820 KB |
Output is correct |
23 |
Correct |
238 ms |
43784 KB |
Output is correct |
24 |
Correct |
134 ms |
30060 KB |
Output is correct |
25 |
Correct |
334 ms |
42448 KB |
Output is correct |
26 |
Correct |
315 ms |
42692 KB |
Output is correct |
27 |
Correct |
347 ms |
48884 KB |
Output is correct |
28 |
Correct |
322 ms |
49076 KB |
Output is correct |
29 |
Correct |
349 ms |
48836 KB |
Output is correct |
30 |
Correct |
377 ms |
48888 KB |
Output is correct |
31 |
Correct |
3 ms |
14940 KB |
Output is correct |
32 |
Correct |
17 ms |
17528 KB |
Output is correct |
33 |
Correct |
45 ms |
22156 KB |
Output is correct |
34 |
Correct |
263 ms |
48804 KB |
Output is correct |
35 |
Correct |
10 ms |
16216 KB |
Output is correct |
36 |
Correct |
50 ms |
21628 KB |
Output is correct |
37 |
Correct |
132 ms |
28596 KB |
Output is correct |
38 |
Correct |
122 ms |
28344 KB |
Output is correct |
39 |
Correct |
169 ms |
33496 KB |
Output is correct |
40 |
Correct |
225 ms |
38604 KB |
Output is correct |
41 |
Correct |
361 ms |
43688 KB |
Output is correct |
42 |
Correct |
378 ms |
48884 KB |
Output is correct |
43 |
Correct |
3 ms |
14936 KB |
Output is correct |
44 |
Correct |
3 ms |
14940 KB |
Output is correct |
45 |
Correct |
3 ms |
14940 KB |
Output is correct |
46 |
Correct |
3 ms |
14940 KB |
Output is correct |
47 |
Correct |
3 ms |
14940 KB |
Output is correct |
48 |
Correct |
3 ms |
14940 KB |
Output is correct |
49 |
Correct |
3 ms |
14936 KB |
Output is correct |
50 |
Correct |
2 ms |
14940 KB |
Output is correct |
51 |
Correct |
3 ms |
14940 KB |
Output is correct |
52 |
Correct |
3 ms |
14964 KB |
Output is correct |
53 |
Correct |
3 ms |
14940 KB |
Output is correct |
54 |
Correct |
5 ms |
15148 KB |
Output is correct |
55 |
Correct |
7 ms |
15196 KB |
Output is correct |
56 |
Correct |
203 ms |
31688 KB |
Output is correct |
57 |
Correct |
283 ms |
39492 KB |
Output is correct |
58 |
Correct |
259 ms |
39336 KB |
Output is correct |
59 |
Correct |
3 ms |
14936 KB |
Output is correct |
60 |
Correct |
3 ms |
14936 KB |
Output is correct |
61 |
Correct |
3 ms |
14940 KB |
Output is correct |
62 |
Correct |
387 ms |
48876 KB |
Output is correct |
63 |
Correct |
416 ms |
48908 KB |
Output is correct |
64 |
Correct |
384 ms |
48812 KB |
Output is correct |
65 |
Correct |
7 ms |
15452 KB |
Output is correct |
66 |
Correct |
10 ms |
15964 KB |
Output is correct |
67 |
Correct |
171 ms |
31748 KB |
Output is correct |
68 |
Correct |
316 ms |
40244 KB |
Output is correct |
69 |
Correct |
502 ms |
48976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
172 ms |
31856 KB |
Output is correct |
10 |
Correct |
11 ms |
16732 KB |
Output is correct |
11 |
Correct |
56 ms |
24004 KB |
Output is correct |
12 |
Correct |
18 ms |
17912 KB |
Output is correct |
13 |
Correct |
31 ms |
21036 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
4 ms |
15192 KB |
Output is correct |
16 |
Correct |
151 ms |
31732 KB |
Output is correct |
17 |
Correct |
315 ms |
48936 KB |
Output is correct |
18 |
Correct |
300 ms |
48804 KB |
Output is correct |
19 |
Correct |
237 ms |
48876 KB |
Output is correct |
20 |
Correct |
443 ms |
54256 KB |
Output is correct |
21 |
Correct |
340 ms |
46448 KB |
Output is correct |
22 |
Correct |
3 ms |
14936 KB |
Output is correct |
23 |
Correct |
45 ms |
20428 KB |
Output is correct |
24 |
Correct |
24 ms |
17996 KB |
Output is correct |
25 |
Correct |
76 ms |
25356 KB |
Output is correct |
26 |
Correct |
143 ms |
32688 KB |
Output is correct |
27 |
Correct |
174 ms |
33720 KB |
Output is correct |
28 |
Correct |
205 ms |
38312 KB |
Output is correct |
29 |
Correct |
298 ms |
43144 KB |
Output is correct |
30 |
Correct |
353 ms |
47788 KB |
Output is correct |
31 |
Correct |
425 ms |
52472 KB |
Output is correct |
32 |
Correct |
474 ms |
52644 KB |
Output is correct |
33 |
Correct |
402 ms |
48804 KB |
Output is correct |
34 |
Correct |
7 ms |
15708 KB |
Output is correct |
35 |
Correct |
15 ms |
16216 KB |
Output is correct |
36 |
Correct |
170 ms |
32748 KB |
Output is correct |
37 |
Correct |
305 ms |
41892 KB |
Output is correct |
38 |
Correct |
458 ms |
51240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
3 ms |
14940 KB |
Output is correct |
3 |
Correct |
3 ms |
14940 KB |
Output is correct |
4 |
Correct |
3 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
3 ms |
14936 KB |
Output is correct |
7 |
Correct |
3 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
172 ms |
31856 KB |
Output is correct |
10 |
Correct |
11 ms |
16732 KB |
Output is correct |
11 |
Correct |
56 ms |
24004 KB |
Output is correct |
12 |
Correct |
18 ms |
17912 KB |
Output is correct |
13 |
Correct |
31 ms |
21036 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
4 ms |
15192 KB |
Output is correct |
16 |
Correct |
151 ms |
31732 KB |
Output is correct |
17 |
Correct |
3 ms |
14936 KB |
Output is correct |
18 |
Correct |
3 ms |
14940 KB |
Output is correct |
19 |
Correct |
3 ms |
14940 KB |
Output is correct |
20 |
Correct |
3 ms |
14940 KB |
Output is correct |
21 |
Correct |
4 ms |
14936 KB |
Output is correct |
22 |
Correct |
3 ms |
14940 KB |
Output is correct |
23 |
Correct |
569 ms |
48888 KB |
Output is correct |
24 |
Correct |
3 ms |
14936 KB |
Output is correct |
25 |
Correct |
4 ms |
15196 KB |
Output is correct |
26 |
Correct |
6 ms |
15196 KB |
Output is correct |
27 |
Correct |
7 ms |
15452 KB |
Output is correct |
28 |
Correct |
141 ms |
28280 KB |
Output is correct |
29 |
Correct |
265 ms |
35200 KB |
Output is correct |
30 |
Correct |
334 ms |
42064 KB |
Output is correct |
31 |
Correct |
434 ms |
48864 KB |
Output is correct |
32 |
Correct |
3 ms |
14940 KB |
Output is correct |
33 |
Correct |
3 ms |
14940 KB |
Output is correct |
34 |
Correct |
3 ms |
14936 KB |
Output is correct |
35 |
Correct |
3 ms |
14936 KB |
Output is correct |
36 |
Correct |
3 ms |
14940 KB |
Output is correct |
37 |
Correct |
3 ms |
14936 KB |
Output is correct |
38 |
Correct |
3 ms |
14940 KB |
Output is correct |
39 |
Correct |
3 ms |
14940 KB |
Output is correct |
40 |
Correct |
3 ms |
14940 KB |
Output is correct |
41 |
Correct |
3 ms |
14940 KB |
Output is correct |
42 |
Correct |
3 ms |
14940 KB |
Output is correct |
43 |
Correct |
4 ms |
15196 KB |
Output is correct |
44 |
Correct |
5 ms |
15196 KB |
Output is correct |
45 |
Correct |
165 ms |
31684 KB |
Output is correct |
46 |
Correct |
287 ms |
39404 KB |
Output is correct |
47 |
Correct |
263 ms |
39336 KB |
Output is correct |
48 |
Correct |
3 ms |
14936 KB |
Output is correct |
49 |
Correct |
3 ms |
15192 KB |
Output is correct |
50 |
Correct |
3 ms |
14940 KB |
Output is correct |
51 |
Correct |
4 ms |
14940 KB |
Output is correct |
52 |
Correct |
3 ms |
14940 KB |
Output is correct |
53 |
Correct |
3 ms |
14940 KB |
Output is correct |
54 |
Correct |
3 ms |
14940 KB |
Output is correct |
55 |
Incorrect |
439 ms |
42636 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |