#include <vector>
#include <map>
#include <queue>
#include "parks.h"
using namespace std;
map<pair<int,int>,int>d,vis;
vector<pair<int,int>>z;
queue<pair<int,int>>Q;
int x1=0,y11=0;
void check(int x,int y)
{
if (d.find({x,y})!=d.end()&&!vis[{x,y}])
{
Q.push({x,y});
vis[{x,y}]=1;
z.push_back({d[{x1,y11}],d[{x,y}]});
}
}
void bfs(int x,int y)
{
Q.push({x,y});
vis[{x,y}]=1;
while (Q.size())
{
x,y;
tie(x,y)=Q.front();
x1=x,y11=y;
Q.pop();
check(x,y-2);
check(x-2,y);
check(x,y+2);
check(x+2,y);
}
}
int construct_roads(vector<int> x, vector<int> y)
{
int n=x.size();
for (int i=0;i<n;i++)
d[{x[i],y[i]}]=i;
int reqx=1e9+10,reqy=1e9+10;
for (int i=0;i<n;i++)
{
if (x[i]<reqx)
{
reqx=x[i];
reqy=y[i];
}
else if (x[i]==reqx&&reqy>y[i])
reqy=y[i];
}
bfs(reqx,reqy);
for (int i=0;i<n;i++)
{
if (!vis[{x[i],y[i]}])
return 0;
}
//cout<<1<<endl;
vis={};
vector<int>u,v,a,b;
for (auto i:z)
{
u.push_back(i.first);
v.push_back(i.second);
pair<int,int>r,q;
r.first=x[i.first],r.second=y[i.first];
q.first=x[i.second],q.second=y[i.second];
if (r.first-q.first==0)
{
a.push_back(r.first-1);
b.push_back((r.second+q.second)/2);
if (vis[{a.back(),b.back()}])
{
a.pop_back();
a.push_back(r.first+1);
if (vis[{a.back(),b.back()}])
return 0;
vis[{a.back(),b.back()}]=1;
}
else
vis[{a.back(),b.back()}]=1;
}
else
{
a.push_back((r.first+q.first)/2);
b.push_back(r.second-1);
if (vis[{a.back(),b.back()}])
{
b.pop_back();
b.push_back(r.second+1);
if (vis[{a.back(),b.back()}])
return 0;
vis[{a.back(),b.back()}]=1;
}
else
vis[{a.back(),b.back()}]=1;
}
}
build(u,v,a,b);
return 1;
}
Compilation message
parks.cpp: In function 'void bfs(int, int)':
parks.cpp:25:3: warning: left operand of comma operator has no effect [-Wunused-value]
25 | x,y;
| ^
parks.cpp:25:6: warning: right operand of comma operator has no effect [-Wunused-value]
25 | x,y;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
177 ms |
21432 KB |
Output is correct |
10 |
Correct |
14 ms |
2396 KB |
Output is correct |
11 |
Correct |
83 ms |
11596 KB |
Output is correct |
12 |
Correct |
20 ms |
3416 KB |
Output is correct |
13 |
Correct |
36 ms |
5972 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
178 ms |
21608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
177 ms |
21432 KB |
Output is correct |
10 |
Correct |
14 ms |
2396 KB |
Output is correct |
11 |
Correct |
83 ms |
11596 KB |
Output is correct |
12 |
Correct |
20 ms |
3416 KB |
Output is correct |
13 |
Correct |
36 ms |
5972 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
178 ms |
21608 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
473 ms |
42992 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
159 ms |
17244 KB |
Output is correct |
29 |
Correct |
255 ms |
25528 KB |
Output is correct |
30 |
Correct |
347 ms |
34316 KB |
Output is correct |
31 |
Correct |
458 ms |
43144 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
172 ms |
21568 KB |
Output is correct |
46 |
Correct |
277 ms |
32556 KB |
Output is correct |
47 |
Correct |
267 ms |
32392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
177 ms |
21432 KB |
Output is correct |
10 |
Correct |
14 ms |
2396 KB |
Output is correct |
11 |
Correct |
83 ms |
11596 KB |
Output is correct |
12 |
Correct |
20 ms |
3416 KB |
Output is correct |
13 |
Correct |
36 ms |
5972 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
178 ms |
21608 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
473 ms |
42992 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
159 ms |
17244 KB |
Output is correct |
29 |
Correct |
255 ms |
25528 KB |
Output is correct |
30 |
Correct |
347 ms |
34316 KB |
Output is correct |
31 |
Correct |
458 ms |
43144 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
172 ms |
21568 KB |
Output is correct |
46 |
Correct |
277 ms |
32556 KB |
Output is correct |
47 |
Correct |
267 ms |
32392 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
604 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
604 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
464 ms |
44504 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
2 ms |
604 KB |
Output is correct |
58 |
Correct |
9 ms |
1528 KB |
Output is correct |
59 |
Correct |
5 ms |
1372 KB |
Output is correct |
60 |
Correct |
202 ms |
22324 KB |
Output is correct |
61 |
Correct |
299 ms |
30820 KB |
Output is correct |
62 |
Correct |
368 ms |
36784 KB |
Output is correct |
63 |
Correct |
459 ms |
44704 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
394 ms |
44656 KB |
Output is correct |
68 |
Correct |
452 ms |
44708 KB |
Output is correct |
69 |
Correct |
415 ms |
44624 KB |
Output is correct |
70 |
Correct |
2 ms |
860 KB |
Output is correct |
71 |
Correct |
4 ms |
1200 KB |
Output is correct |
72 |
Correct |
176 ms |
22096 KB |
Output is correct |
73 |
Correct |
284 ms |
33320 KB |
Output is correct |
74 |
Correct |
414 ms |
44808 KB |
Output is correct |
75 |
Correct |
437 ms |
44548 KB |
Output is correct |
76 |
Correct |
438 ms |
44628 KB |
Output is correct |
77 |
Correct |
3 ms |
856 KB |
Output is correct |
78 |
Correct |
4 ms |
1312 KB |
Output is correct |
79 |
Correct |
179 ms |
22224 KB |
Output is correct |
80 |
Correct |
291 ms |
33576 KB |
Output is correct |
81 |
Correct |
399 ms |
44712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
177 ms |
21432 KB |
Output is correct |
10 |
Correct |
14 ms |
2396 KB |
Output is correct |
11 |
Correct |
83 ms |
11596 KB |
Output is correct |
12 |
Correct |
20 ms |
3416 KB |
Output is correct |
13 |
Correct |
36 ms |
5972 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
178 ms |
21608 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
415 ms |
43968 KB |
Output is correct |
21 |
Correct |
408 ms |
43680 KB |
Output is correct |
22 |
Correct |
418 ms |
43752 KB |
Output is correct |
23 |
Correct |
340 ms |
36444 KB |
Output is correct |
24 |
Correct |
90 ms |
15952 KB |
Output is correct |
25 |
Correct |
91 ms |
15952 KB |
Output is correct |
26 |
Correct |
90 ms |
16080 KB |
Output is correct |
27 |
Correct |
527 ms |
42908 KB |
Output is correct |
28 |
Correct |
544 ms |
42912 KB |
Output is correct |
29 |
Correct |
569 ms |
42932 KB |
Output is correct |
30 |
Correct |
564 ms |
42916 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Incorrect |
18 ms |
2648 KB |
Solution announced impossible, but it is possible. |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
177 ms |
21432 KB |
Output is correct |
10 |
Correct |
14 ms |
2396 KB |
Output is correct |
11 |
Correct |
83 ms |
11596 KB |
Output is correct |
12 |
Correct |
20 ms |
3416 KB |
Output is correct |
13 |
Correct |
36 ms |
5972 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
178 ms |
21608 KB |
Output is correct |
17 |
Correct |
428 ms |
43168 KB |
Output is correct |
18 |
Correct |
411 ms |
43424 KB |
Output is correct |
19 |
Correct |
407 ms |
43700 KB |
Output is correct |
20 |
Correct |
524 ms |
41772 KB |
Output is correct |
21 |
Correct |
525 ms |
37660 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Incorrect |
45 ms |
4796 KB |
Solution announced impossible, but it is possible. |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
177 ms |
21432 KB |
Output is correct |
10 |
Correct |
14 ms |
2396 KB |
Output is correct |
11 |
Correct |
83 ms |
11596 KB |
Output is correct |
12 |
Correct |
20 ms |
3416 KB |
Output is correct |
13 |
Correct |
36 ms |
5972 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
178 ms |
21608 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
473 ms |
42992 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
2 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
604 KB |
Output is correct |
27 |
Correct |
2 ms |
604 KB |
Output is correct |
28 |
Correct |
159 ms |
17244 KB |
Output is correct |
29 |
Correct |
255 ms |
25528 KB |
Output is correct |
30 |
Correct |
347 ms |
34316 KB |
Output is correct |
31 |
Correct |
458 ms |
43144 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
604 KB |
Output is correct |
44 |
Correct |
1 ms |
604 KB |
Output is correct |
45 |
Correct |
172 ms |
21568 KB |
Output is correct |
46 |
Correct |
277 ms |
32556 KB |
Output is correct |
47 |
Correct |
267 ms |
32392 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
604 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
604 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
464 ms |
44504 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
2 ms |
604 KB |
Output is correct |
58 |
Correct |
9 ms |
1528 KB |
Output is correct |
59 |
Correct |
5 ms |
1372 KB |
Output is correct |
60 |
Correct |
202 ms |
22324 KB |
Output is correct |
61 |
Correct |
299 ms |
30820 KB |
Output is correct |
62 |
Correct |
368 ms |
36784 KB |
Output is correct |
63 |
Correct |
459 ms |
44704 KB |
Output is correct |
64 |
Correct |
0 ms |
344 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
348 KB |
Output is correct |
67 |
Correct |
394 ms |
44656 KB |
Output is correct |
68 |
Correct |
452 ms |
44708 KB |
Output is correct |
69 |
Correct |
415 ms |
44624 KB |
Output is correct |
70 |
Correct |
2 ms |
860 KB |
Output is correct |
71 |
Correct |
4 ms |
1200 KB |
Output is correct |
72 |
Correct |
176 ms |
22096 KB |
Output is correct |
73 |
Correct |
284 ms |
33320 KB |
Output is correct |
74 |
Correct |
414 ms |
44808 KB |
Output is correct |
75 |
Correct |
437 ms |
44548 KB |
Output is correct |
76 |
Correct |
438 ms |
44628 KB |
Output is correct |
77 |
Correct |
3 ms |
856 KB |
Output is correct |
78 |
Correct |
4 ms |
1312 KB |
Output is correct |
79 |
Correct |
179 ms |
22224 KB |
Output is correct |
80 |
Correct |
291 ms |
33576 KB |
Output is correct |
81 |
Correct |
399 ms |
44712 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
415 ms |
43968 KB |
Output is correct |
86 |
Correct |
408 ms |
43680 KB |
Output is correct |
87 |
Correct |
418 ms |
43752 KB |
Output is correct |
88 |
Correct |
340 ms |
36444 KB |
Output is correct |
89 |
Correct |
90 ms |
15952 KB |
Output is correct |
90 |
Correct |
91 ms |
15952 KB |
Output is correct |
91 |
Correct |
90 ms |
16080 KB |
Output is correct |
92 |
Correct |
527 ms |
42908 KB |
Output is correct |
93 |
Correct |
544 ms |
42912 KB |
Output is correct |
94 |
Correct |
569 ms |
42932 KB |
Output is correct |
95 |
Correct |
564 ms |
42916 KB |
Output is correct |
96 |
Correct |
0 ms |
344 KB |
Output is correct |
97 |
Incorrect |
18 ms |
2648 KB |
Solution announced impossible, but it is possible. |
98 |
Halted |
0 ms |
0 KB |
- |