#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
const int mxn=2e5+5;
int color[mxn],say;
map<pii,int>mp;
map<int,bool>l,r;
vector<int>vt[mxn];
void dfs(int u){
color[u]=1;
say++;
for(int v:vt[u]){
if(!color[v]){
dfs(v);
}
}
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
vector<int>a,b;
for(int i=0;i<x.size();i++){
mp[{x[i],y[i]}]=i;
if(x[i]==2){
a.pb(y[i]);
l[y[i]]=1;
}
else{
b.pb(y[i]);
r[y[i]]=1;
}
}
sort(all(a));
sort(all(b));
vector<int>u,v,ax,bx;
for(int i=1;i<a.size();i++){
if(a[i]-a[i-1]==2){
u.pb(mp[{2,a[i-1]}]);
v.pb(mp[{2,a[i]}]);
vt[u.back()].pb(v.back());
vt[v.back()].pb(u.back());
ax.pb(1);
bx.pb((a[i]+a[i-1])/2);
}
}
for(int i=1;i<b.size();i++){
if(b[i]-b[i-1]==2){
u.pb(mp[{4,b[i-1]}]);
v.pb(mp[{4,b[i]}]);
vt[u.back()].pb(v.back());
vt[v.back()].pb(u.back());
ax.pb(5);
bx.pb((b[i]+b[i-1])/2);
}
}
for(int i=2;i<=200000;i+=2){
if(l[i]&&r[i]){
u.pb(mp[{2,i}]);
v.pb(mp[{4,i}]);
vt[u.back()].pb(v.back());
vt[v.back()].pb(u.back());
ax.pb(3);
bx.pb(i-1);
}
}
dfs(0);
if(say!=x.size()){
return 0;
}
build(u,v,ax,bx);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0;i<x.size();i++){
| ~^~~~~~~~~
parks.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=1;i<a.size();i++){
| ~^~~~~~~~~
parks.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=1;i<b.size();i++){
| ~^~~~~~~~~
parks.cpp:74:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | if(say!=x.size()){
| ~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
9684 KB |
Output is correct |
2 |
Correct |
20 ms |
9684 KB |
Output is correct |
3 |
Correct |
24 ms |
9584 KB |
Output is correct |
4 |
Correct |
20 ms |
9608 KB |
Output is correct |
5 |
Correct |
23 ms |
9612 KB |
Output is correct |
6 |
Correct |
21 ms |
9676 KB |
Output is correct |
7 |
Correct |
23 ms |
9676 KB |
Output is correct |
8 |
Correct |
22 ms |
9660 KB |
Output is correct |
9 |
Correct |
200 ms |
34648 KB |
Output is correct |
10 |
Correct |
34 ms |
12364 KB |
Output is correct |
11 |
Correct |
92 ms |
23168 KB |
Output is correct |
12 |
Correct |
36 ms |
13680 KB |
Output is correct |
13 |
Correct |
61 ms |
18908 KB |
Output is correct |
14 |
Correct |
21 ms |
9812 KB |
Output is correct |
15 |
Correct |
24 ms |
9968 KB |
Output is correct |
16 |
Correct |
231 ms |
33364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
9684 KB |
Output is correct |
2 |
Correct |
20 ms |
9684 KB |
Output is correct |
3 |
Correct |
24 ms |
9584 KB |
Output is correct |
4 |
Correct |
20 ms |
9608 KB |
Output is correct |
5 |
Correct |
23 ms |
9612 KB |
Output is correct |
6 |
Correct |
21 ms |
9676 KB |
Output is correct |
7 |
Correct |
23 ms |
9676 KB |
Output is correct |
8 |
Correct |
22 ms |
9660 KB |
Output is correct |
9 |
Correct |
200 ms |
34648 KB |
Output is correct |
10 |
Correct |
34 ms |
12364 KB |
Output is correct |
11 |
Correct |
92 ms |
23168 KB |
Output is correct |
12 |
Correct |
36 ms |
13680 KB |
Output is correct |
13 |
Correct |
61 ms |
18908 KB |
Output is correct |
14 |
Correct |
21 ms |
9812 KB |
Output is correct |
15 |
Correct |
24 ms |
9968 KB |
Output is correct |
16 |
Correct |
231 ms |
33364 KB |
Output is correct |
17 |
Correct |
24 ms |
9768 KB |
Output is correct |
18 |
Correct |
23 ms |
9612 KB |
Output is correct |
19 |
Correct |
21 ms |
9644 KB |
Output is correct |
20 |
Correct |
27 ms |
9712 KB |
Output is correct |
21 |
Correct |
25 ms |
9672 KB |
Output is correct |
22 |
Correct |
24 ms |
9684 KB |
Output is correct |
23 |
Correct |
519 ms |
59828 KB |
Output is correct |
24 |
Correct |
20 ms |
9684 KB |
Output is correct |
25 |
Correct |
23 ms |
9924 KB |
Output is correct |
26 |
Correct |
28 ms |
10256 KB |
Output is correct |
27 |
Correct |
24 ms |
10396 KB |
Output is correct |
28 |
Correct |
208 ms |
29772 KB |
Output is correct |
29 |
Correct |
275 ms |
39784 KB |
Output is correct |
30 |
Correct |
390 ms |
49980 KB |
Output is correct |
31 |
Correct |
512 ms |
59852 KB |
Output is correct |
32 |
Correct |
20 ms |
9676 KB |
Output is correct |
33 |
Correct |
21 ms |
9668 KB |
Output is correct |
34 |
Correct |
22 ms |
9640 KB |
Output is correct |
35 |
Correct |
26 ms |
9628 KB |
Output is correct |
36 |
Correct |
23 ms |
9596 KB |
Output is correct |
37 |
Correct |
22 ms |
9596 KB |
Output is correct |
38 |
Correct |
20 ms |
9572 KB |
Output is correct |
39 |
Correct |
21 ms |
9688 KB |
Output is correct |
40 |
Correct |
21 ms |
9632 KB |
Output is correct |
41 |
Correct |
20 ms |
9676 KB |
Output is correct |
42 |
Correct |
22 ms |
9684 KB |
Output is correct |
43 |
Correct |
24 ms |
9956 KB |
Output is correct |
44 |
Correct |
25 ms |
10196 KB |
Output is correct |
45 |
Correct |
210 ms |
32128 KB |
Output is correct |
46 |
Correct |
329 ms |
42416 KB |
Output is correct |
47 |
Correct |
328 ms |
42192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
9684 KB |
Output is correct |
2 |
Correct |
20 ms |
9684 KB |
Output is correct |
3 |
Correct |
24 ms |
9584 KB |
Output is correct |
4 |
Correct |
20 ms |
9608 KB |
Output is correct |
5 |
Correct |
23 ms |
9612 KB |
Output is correct |
6 |
Correct |
21 ms |
9676 KB |
Output is correct |
7 |
Correct |
23 ms |
9676 KB |
Output is correct |
8 |
Correct |
22 ms |
9660 KB |
Output is correct |
9 |
Correct |
200 ms |
34648 KB |
Output is correct |
10 |
Correct |
34 ms |
12364 KB |
Output is correct |
11 |
Correct |
92 ms |
23168 KB |
Output is correct |
12 |
Correct |
36 ms |
13680 KB |
Output is correct |
13 |
Correct |
61 ms |
18908 KB |
Output is correct |
14 |
Correct |
21 ms |
9812 KB |
Output is correct |
15 |
Correct |
24 ms |
9968 KB |
Output is correct |
16 |
Correct |
231 ms |
33364 KB |
Output is correct |
17 |
Correct |
24 ms |
9768 KB |
Output is correct |
18 |
Correct |
23 ms |
9612 KB |
Output is correct |
19 |
Correct |
21 ms |
9644 KB |
Output is correct |
20 |
Correct |
27 ms |
9712 KB |
Output is correct |
21 |
Correct |
25 ms |
9672 KB |
Output is correct |
22 |
Correct |
24 ms |
9684 KB |
Output is correct |
23 |
Correct |
519 ms |
59828 KB |
Output is correct |
24 |
Correct |
20 ms |
9684 KB |
Output is correct |
25 |
Correct |
23 ms |
9924 KB |
Output is correct |
26 |
Correct |
28 ms |
10256 KB |
Output is correct |
27 |
Correct |
24 ms |
10396 KB |
Output is correct |
28 |
Correct |
208 ms |
29772 KB |
Output is correct |
29 |
Correct |
275 ms |
39784 KB |
Output is correct |
30 |
Correct |
390 ms |
49980 KB |
Output is correct |
31 |
Correct |
512 ms |
59852 KB |
Output is correct |
32 |
Correct |
20 ms |
9676 KB |
Output is correct |
33 |
Correct |
21 ms |
9668 KB |
Output is correct |
34 |
Correct |
22 ms |
9640 KB |
Output is correct |
35 |
Correct |
26 ms |
9628 KB |
Output is correct |
36 |
Correct |
23 ms |
9596 KB |
Output is correct |
37 |
Correct |
22 ms |
9596 KB |
Output is correct |
38 |
Correct |
20 ms |
9572 KB |
Output is correct |
39 |
Correct |
21 ms |
9688 KB |
Output is correct |
40 |
Correct |
21 ms |
9632 KB |
Output is correct |
41 |
Correct |
20 ms |
9676 KB |
Output is correct |
42 |
Correct |
22 ms |
9684 KB |
Output is correct |
43 |
Correct |
24 ms |
9956 KB |
Output is correct |
44 |
Correct |
25 ms |
10196 KB |
Output is correct |
45 |
Correct |
210 ms |
32128 KB |
Output is correct |
46 |
Correct |
329 ms |
42416 KB |
Output is correct |
47 |
Correct |
328 ms |
42192 KB |
Output is correct |
48 |
Incorrect |
22 ms |
9600 KB |
Solution announced impossible, but it is possible. |
49 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
9684 KB |
Output is correct |
2 |
Correct |
20 ms |
9684 KB |
Output is correct |
3 |
Correct |
24 ms |
9584 KB |
Output is correct |
4 |
Correct |
20 ms |
9608 KB |
Output is correct |
5 |
Correct |
23 ms |
9612 KB |
Output is correct |
6 |
Correct |
21 ms |
9676 KB |
Output is correct |
7 |
Correct |
23 ms |
9676 KB |
Output is correct |
8 |
Correct |
22 ms |
9660 KB |
Output is correct |
9 |
Correct |
200 ms |
34648 KB |
Output is correct |
10 |
Correct |
34 ms |
12364 KB |
Output is correct |
11 |
Correct |
92 ms |
23168 KB |
Output is correct |
12 |
Correct |
36 ms |
13680 KB |
Output is correct |
13 |
Correct |
61 ms |
18908 KB |
Output is correct |
14 |
Correct |
21 ms |
9812 KB |
Output is correct |
15 |
Correct |
24 ms |
9968 KB |
Output is correct |
16 |
Correct |
231 ms |
33364 KB |
Output is correct |
17 |
Incorrect |
23 ms |
9604 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
9684 KB |
Output is correct |
2 |
Correct |
20 ms |
9684 KB |
Output is correct |
3 |
Correct |
24 ms |
9584 KB |
Output is correct |
4 |
Correct |
20 ms |
9608 KB |
Output is correct |
5 |
Correct |
23 ms |
9612 KB |
Output is correct |
6 |
Correct |
21 ms |
9676 KB |
Output is correct |
7 |
Correct |
23 ms |
9676 KB |
Output is correct |
8 |
Correct |
22 ms |
9660 KB |
Output is correct |
9 |
Correct |
200 ms |
34648 KB |
Output is correct |
10 |
Correct |
34 ms |
12364 KB |
Output is correct |
11 |
Correct |
92 ms |
23168 KB |
Output is correct |
12 |
Correct |
36 ms |
13680 KB |
Output is correct |
13 |
Correct |
61 ms |
18908 KB |
Output is correct |
14 |
Correct |
21 ms |
9812 KB |
Output is correct |
15 |
Correct |
24 ms |
9968 KB |
Output is correct |
16 |
Correct |
231 ms |
33364 KB |
Output is correct |
17 |
Incorrect |
287 ms |
40904 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
9684 KB |
Output is correct |
2 |
Correct |
20 ms |
9684 KB |
Output is correct |
3 |
Correct |
24 ms |
9584 KB |
Output is correct |
4 |
Correct |
20 ms |
9608 KB |
Output is correct |
5 |
Correct |
23 ms |
9612 KB |
Output is correct |
6 |
Correct |
21 ms |
9676 KB |
Output is correct |
7 |
Correct |
23 ms |
9676 KB |
Output is correct |
8 |
Correct |
22 ms |
9660 KB |
Output is correct |
9 |
Correct |
200 ms |
34648 KB |
Output is correct |
10 |
Correct |
34 ms |
12364 KB |
Output is correct |
11 |
Correct |
92 ms |
23168 KB |
Output is correct |
12 |
Correct |
36 ms |
13680 KB |
Output is correct |
13 |
Correct |
61 ms |
18908 KB |
Output is correct |
14 |
Correct |
21 ms |
9812 KB |
Output is correct |
15 |
Correct |
24 ms |
9968 KB |
Output is correct |
16 |
Correct |
231 ms |
33364 KB |
Output is correct |
17 |
Correct |
24 ms |
9768 KB |
Output is correct |
18 |
Correct |
23 ms |
9612 KB |
Output is correct |
19 |
Correct |
21 ms |
9644 KB |
Output is correct |
20 |
Correct |
27 ms |
9712 KB |
Output is correct |
21 |
Correct |
25 ms |
9672 KB |
Output is correct |
22 |
Correct |
24 ms |
9684 KB |
Output is correct |
23 |
Correct |
519 ms |
59828 KB |
Output is correct |
24 |
Correct |
20 ms |
9684 KB |
Output is correct |
25 |
Correct |
23 ms |
9924 KB |
Output is correct |
26 |
Correct |
28 ms |
10256 KB |
Output is correct |
27 |
Correct |
24 ms |
10396 KB |
Output is correct |
28 |
Correct |
208 ms |
29772 KB |
Output is correct |
29 |
Correct |
275 ms |
39784 KB |
Output is correct |
30 |
Correct |
390 ms |
49980 KB |
Output is correct |
31 |
Correct |
512 ms |
59852 KB |
Output is correct |
32 |
Correct |
20 ms |
9676 KB |
Output is correct |
33 |
Correct |
21 ms |
9668 KB |
Output is correct |
34 |
Correct |
22 ms |
9640 KB |
Output is correct |
35 |
Correct |
26 ms |
9628 KB |
Output is correct |
36 |
Correct |
23 ms |
9596 KB |
Output is correct |
37 |
Correct |
22 ms |
9596 KB |
Output is correct |
38 |
Correct |
20 ms |
9572 KB |
Output is correct |
39 |
Correct |
21 ms |
9688 KB |
Output is correct |
40 |
Correct |
21 ms |
9632 KB |
Output is correct |
41 |
Correct |
20 ms |
9676 KB |
Output is correct |
42 |
Correct |
22 ms |
9684 KB |
Output is correct |
43 |
Correct |
24 ms |
9956 KB |
Output is correct |
44 |
Correct |
25 ms |
10196 KB |
Output is correct |
45 |
Correct |
210 ms |
32128 KB |
Output is correct |
46 |
Correct |
329 ms |
42416 KB |
Output is correct |
47 |
Correct |
328 ms |
42192 KB |
Output is correct |
48 |
Incorrect |
22 ms |
9600 KB |
Solution announced impossible, but it is possible. |
49 |
Halted |
0 ms |
0 KB |
- |