#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include "parks.h"
using namespace std;
map<pair<int,int>,int>d,vis;
vector<pair<int,int>>z;
int x1=0,y11=0;
bool check(int x,int y)
{
if (d.find({x,y})!=d.end()&&!vis[{x,y}])
{
vis[{x,y}]=1;
z.push_back({d[{x1,y11}],d[{x,y}]});
return 1;
}
return 0;
}
vector<pair<int,int>>i={{0,-2},{0,2},{2,0},{-2,0}};
void bfs(int x,int y)
{
vis[{x,y}]=1;
for (int j=0;j<4;j++)
{
x1=x;
y11=y;
if (check(x+i[j].first,y+i[j].second))
bfs(x+i[j].first,y+i[j].second);
}
}
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];
}
sort(begin(i),end(i));
do
{
vis={};
z={};
bfs(reqx,reqy);
bool w=1;
for (int i=0;i<n;i++)
{
if (!vis[{x[i],y[i]}])
w=0;
}
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()}])
w=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()}])
w=0;
vis[{a.back(),b.back()}]=1;
}
else
vis[{a.back(),b.back()}]=1;
}
}
if (w==1)
{
build(u,v,a,b);
return 1;
}
}
while(next_permutation(begin(i),end(i)));
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
364 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 |
424 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
197 ms |
30220 KB |
Output is correct |
10 |
Correct |
14 ms |
3420 KB |
Output is correct |
11 |
Correct |
99 ms |
16416 KB |
Output is correct |
12 |
Correct |
22 ms |
4696 KB |
Output is correct |
13 |
Correct |
787 ms |
9616 KB |
Output is correct |
14 |
Correct |
9 ms |
600 KB |
Output is correct |
15 |
Correct |
13 ms |
768 KB |
Output is correct |
16 |
Correct |
198 ms |
30076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
364 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 |
424 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
197 ms |
30220 KB |
Output is correct |
10 |
Correct |
14 ms |
3420 KB |
Output is correct |
11 |
Correct |
99 ms |
16416 KB |
Output is correct |
12 |
Correct |
22 ms |
4696 KB |
Output is correct |
13 |
Correct |
787 ms |
9616 KB |
Output is correct |
14 |
Correct |
9 ms |
600 KB |
Output is correct |
15 |
Correct |
13 ms |
768 KB |
Output is correct |
16 |
Correct |
198 ms |
30076 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 |
544 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 |
551 ms |
60268 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
704 KB |
Output is correct |
26 |
Correct |
33 ms |
860 KB |
Output is correct |
27 |
Correct |
26 ms |
856 KB |
Output is correct |
28 |
Correct |
181 ms |
24096 KB |
Output is correct |
29 |
Correct |
287 ms |
35992 KB |
Output is correct |
30 |
Correct |
393 ms |
48072 KB |
Output is correct |
31 |
Correct |
549 ms |
60276 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 |
348 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 |
344 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 |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
21 ms |
800 KB |
Output is correct |
44 |
Correct |
21 ms |
860 KB |
Output is correct |
45 |
Correct |
184 ms |
28556 KB |
Output is correct |
46 |
Correct |
308 ms |
41412 KB |
Output is correct |
47 |
Correct |
293 ms |
41556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
364 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 |
424 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
197 ms |
30220 KB |
Output is correct |
10 |
Correct |
14 ms |
3420 KB |
Output is correct |
11 |
Correct |
99 ms |
16416 KB |
Output is correct |
12 |
Correct |
22 ms |
4696 KB |
Output is correct |
13 |
Correct |
787 ms |
9616 KB |
Output is correct |
14 |
Correct |
9 ms |
600 KB |
Output is correct |
15 |
Correct |
13 ms |
768 KB |
Output is correct |
16 |
Correct |
198 ms |
30076 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 |
544 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 |
551 ms |
60268 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
704 KB |
Output is correct |
26 |
Correct |
33 ms |
860 KB |
Output is correct |
27 |
Correct |
26 ms |
856 KB |
Output is correct |
28 |
Correct |
181 ms |
24096 KB |
Output is correct |
29 |
Correct |
287 ms |
35992 KB |
Output is correct |
30 |
Correct |
393 ms |
48072 KB |
Output is correct |
31 |
Correct |
549 ms |
60276 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 |
348 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 |
344 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 |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
21 ms |
800 KB |
Output is correct |
44 |
Correct |
21 ms |
860 KB |
Output is correct |
45 |
Correct |
184 ms |
28556 KB |
Output is correct |
46 |
Correct |
308 ms |
41412 KB |
Output is correct |
47 |
Correct |
293 ms |
41556 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
420 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 |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
523 ms |
60296 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
3 ms |
860 KB |
Output is correct |
58 |
Correct |
9 ms |
2048 KB |
Output is correct |
59 |
Correct |
80 ms |
1884 KB |
Output is correct |
60 |
Correct |
231 ms |
30080 KB |
Output is correct |
61 |
Correct |
311 ms |
41376 KB |
Output is correct |
62 |
Correct |
404 ms |
49576 KB |
Output is correct |
63 |
Correct |
517 ms |
60076 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
424 KB |
Output is correct |
67 |
Correct |
449 ms |
60068 KB |
Output is correct |
68 |
Correct |
475 ms |
52228 KB |
Output is correct |
69 |
Correct |
452 ms |
55924 KB |
Output is correct |
70 |
Correct |
49 ms |
1116 KB |
Output is correct |
71 |
Correct |
70 ms |
1628 KB |
Output is correct |
72 |
Correct |
200 ms |
26808 KB |
Output is correct |
73 |
Correct |
333 ms |
40484 KB |
Output is correct |
74 |
Correct |
499 ms |
53920 KB |
Output is correct |
75 |
Correct |
531 ms |
56988 KB |
Output is correct |
76 |
Correct |
481 ms |
60104 KB |
Output is correct |
77 |
Correct |
72 ms |
1112 KB |
Output is correct |
78 |
Correct |
73 ms |
1880 KB |
Output is correct |
79 |
Correct |
198 ms |
26416 KB |
Output is correct |
80 |
Correct |
325 ms |
39712 KB |
Output is correct |
81 |
Correct |
438 ms |
52892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
364 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 |
424 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
197 ms |
30220 KB |
Output is correct |
10 |
Correct |
14 ms |
3420 KB |
Output is correct |
11 |
Correct |
99 ms |
16416 KB |
Output is correct |
12 |
Correct |
22 ms |
4696 KB |
Output is correct |
13 |
Correct |
787 ms |
9616 KB |
Output is correct |
14 |
Correct |
9 ms |
600 KB |
Output is correct |
15 |
Correct |
13 ms |
768 KB |
Output is correct |
16 |
Correct |
198 ms |
30076 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
604 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
525 ms |
61940 KB |
Output is correct |
21 |
Correct |
477 ms |
53476 KB |
Output is correct |
22 |
Correct |
480 ms |
61344 KB |
Output is correct |
23 |
Correct |
385 ms |
48368 KB |
Output is correct |
24 |
Correct |
2536 ms |
30128 KB |
Output is correct |
25 |
Correct |
2196 ms |
30412 KB |
Output is correct |
26 |
Correct |
2093 ms |
30176 KB |
Output is correct |
27 |
Correct |
444 ms |
44616 KB |
Output is correct |
28 |
Correct |
396 ms |
44452 KB |
Output is correct |
29 |
Correct |
575 ms |
44676 KB |
Output is correct |
30 |
Correct |
575 ms |
44616 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
396 ms |
3432 KB |
Solution announced impossible, but it is possible. |
33 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
364 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 |
424 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
197 ms |
30220 KB |
Output is correct |
10 |
Correct |
14 ms |
3420 KB |
Output is correct |
11 |
Correct |
99 ms |
16416 KB |
Output is correct |
12 |
Correct |
22 ms |
4696 KB |
Output is correct |
13 |
Correct |
787 ms |
9616 KB |
Output is correct |
14 |
Correct |
9 ms |
600 KB |
Output is correct |
15 |
Correct |
13 ms |
768 KB |
Output is correct |
16 |
Correct |
198 ms |
30076 KB |
Output is correct |
17 |
Correct |
502 ms |
60636 KB |
Output is correct |
18 |
Correct |
482 ms |
57468 KB |
Output is correct |
19 |
Correct |
491 ms |
61360 KB |
Output is correct |
20 |
Correct |
481 ms |
53564 KB |
Output is correct |
21 |
Correct |
425 ms |
46432 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Incorrect |
932 ms |
7044 KB |
Solution announced impossible, but it is possible. |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
364 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 |
424 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
197 ms |
30220 KB |
Output is correct |
10 |
Correct |
14 ms |
3420 KB |
Output is correct |
11 |
Correct |
99 ms |
16416 KB |
Output is correct |
12 |
Correct |
22 ms |
4696 KB |
Output is correct |
13 |
Correct |
787 ms |
9616 KB |
Output is correct |
14 |
Correct |
9 ms |
600 KB |
Output is correct |
15 |
Correct |
13 ms |
768 KB |
Output is correct |
16 |
Correct |
198 ms |
30076 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 |
544 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 |
551 ms |
60268 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
704 KB |
Output is correct |
26 |
Correct |
33 ms |
860 KB |
Output is correct |
27 |
Correct |
26 ms |
856 KB |
Output is correct |
28 |
Correct |
181 ms |
24096 KB |
Output is correct |
29 |
Correct |
287 ms |
35992 KB |
Output is correct |
30 |
Correct |
393 ms |
48072 KB |
Output is correct |
31 |
Correct |
549 ms |
60276 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 |
348 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 |
344 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 |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
21 ms |
800 KB |
Output is correct |
44 |
Correct |
21 ms |
860 KB |
Output is correct |
45 |
Correct |
184 ms |
28556 KB |
Output is correct |
46 |
Correct |
308 ms |
41412 KB |
Output is correct |
47 |
Correct |
293 ms |
41556 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
420 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 |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
523 ms |
60296 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
3 ms |
860 KB |
Output is correct |
58 |
Correct |
9 ms |
2048 KB |
Output is correct |
59 |
Correct |
80 ms |
1884 KB |
Output is correct |
60 |
Correct |
231 ms |
30080 KB |
Output is correct |
61 |
Correct |
311 ms |
41376 KB |
Output is correct |
62 |
Correct |
404 ms |
49576 KB |
Output is correct |
63 |
Correct |
517 ms |
60076 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
0 ms |
424 KB |
Output is correct |
67 |
Correct |
449 ms |
60068 KB |
Output is correct |
68 |
Correct |
475 ms |
52228 KB |
Output is correct |
69 |
Correct |
452 ms |
55924 KB |
Output is correct |
70 |
Correct |
49 ms |
1116 KB |
Output is correct |
71 |
Correct |
70 ms |
1628 KB |
Output is correct |
72 |
Correct |
200 ms |
26808 KB |
Output is correct |
73 |
Correct |
333 ms |
40484 KB |
Output is correct |
74 |
Correct |
499 ms |
53920 KB |
Output is correct |
75 |
Correct |
531 ms |
56988 KB |
Output is correct |
76 |
Correct |
481 ms |
60104 KB |
Output is correct |
77 |
Correct |
72 ms |
1112 KB |
Output is correct |
78 |
Correct |
73 ms |
1880 KB |
Output is correct |
79 |
Correct |
198 ms |
26416 KB |
Output is correct |
80 |
Correct |
325 ms |
39712 KB |
Output is correct |
81 |
Correct |
438 ms |
52892 KB |
Output is correct |
82 |
Correct |
0 ms |
344 KB |
Output is correct |
83 |
Correct |
0 ms |
604 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
525 ms |
61940 KB |
Output is correct |
86 |
Correct |
477 ms |
53476 KB |
Output is correct |
87 |
Correct |
480 ms |
61344 KB |
Output is correct |
88 |
Correct |
385 ms |
48368 KB |
Output is correct |
89 |
Correct |
2536 ms |
30128 KB |
Output is correct |
90 |
Correct |
2196 ms |
30412 KB |
Output is correct |
91 |
Correct |
2093 ms |
30176 KB |
Output is correct |
92 |
Correct |
444 ms |
44616 KB |
Output is correct |
93 |
Correct |
396 ms |
44452 KB |
Output is correct |
94 |
Correct |
575 ms |
44676 KB |
Output is correct |
95 |
Correct |
575 ms |
44616 KB |
Output is correct |
96 |
Correct |
0 ms |
348 KB |
Output is correct |
97 |
Incorrect |
396 ms |
3432 KB |
Solution announced impossible, but it is possible. |
98 |
Halted |
0 ms |
0 KB |
- |