#include "parks.h"
#include <bits/stdc++.h>
#define pb push_back
#define ll int
#define ins insert
#define sz size()
#define vll vector<ll>
#define sc second
using namespace std;
const int N=2e5+5;
const int inf=1e9;
map<pair<ll,ll>, ll> f;
vll xx, yy;
ll xd[4] = {0, 2, 0, -2}, yd[4] = {2, 0, -2, 0};
ll bx[2][4] = {{-1, 1, 1, -1}, {1, 1, -1, -1}};
ll by[2][4] = {{ 1, 1, -1, -1}, {1, -1, -1, 1}};
set<pair<ll,ll>> vis;
vll v,u,a,b;
ll n,c;
bool ok(ll x,ll y){
bool free = (vis.find({x, y}) == vis.end());
if(x % 2) return free;
return free && f[{x,y}];
}
void dfs(ll x, ll y){
c++;
for(ll i=0;i<4;i++){
ll nx = x + xd[i], ny = y + yd[i];
ll p = (x + y) / 2 % 2;
ll aa = x + bx[p][i], bb = y + by[p][i];
if(!ok(nx, ny) || !ok(aa, bb)) continue;
v.pb(f[{x,y}]-1);
u.pb(f[{nx,ny}]-1);
a.pb(aa);
b.pb(bb);
vis.ins({aa, bb});
vis.ins({nx, ny});
dfs(nx, ny);
}
}
int construct_roads(vector<int> X, vector<int> Y) {
n=X.size();
for(int i=0;i<(int)X.size();i++){
f[{X[i], Y[i]}] = i + 1;
}
xx.pb(0);
yy.pb(0);
for(auto i : X) xx.pb(i);
for(auto i : Y) yy.pb(i);
dfs(xx[1], yy[1]);
if(c != n) return 0;
build(u, v, a, b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
400 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 |
191 ms |
45820 KB |
Output is correct |
10 |
Correct |
12 ms |
5208 KB |
Output is correct |
11 |
Correct |
92 ms |
25176 KB |
Output is correct |
12 |
Correct |
22 ms |
7516 KB |
Output is correct |
13 |
Correct |
40 ms |
14672 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
172 ms |
41316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
400 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 |
191 ms |
45820 KB |
Output is correct |
10 |
Correct |
12 ms |
5208 KB |
Output is correct |
11 |
Correct |
92 ms |
25176 KB |
Output is correct |
12 |
Correct |
22 ms |
7516 KB |
Output is correct |
13 |
Correct |
40 ms |
14672 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
172 ms |
41316 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 |
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 |
366 ms |
68184 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
1 ms |
860 KB |
Output is correct |
28 |
Correct |
122 ms |
27992 KB |
Output is correct |
29 |
Correct |
184 ms |
40280 KB |
Output is correct |
30 |
Correct |
264 ms |
55120 KB |
Output is correct |
31 |
Correct |
367 ms |
67220 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 |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 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 |
1 ms |
860 KB |
Output is correct |
44 |
Correct |
1 ms |
860 KB |
Output is correct |
45 |
Correct |
163 ms |
38548 KB |
Output is correct |
46 |
Correct |
270 ms |
56660 KB |
Output is correct |
47 |
Correct |
240 ms |
56140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
400 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 |
191 ms |
45820 KB |
Output is correct |
10 |
Correct |
12 ms |
5208 KB |
Output is correct |
11 |
Correct |
92 ms |
25176 KB |
Output is correct |
12 |
Correct |
22 ms |
7516 KB |
Output is correct |
13 |
Correct |
40 ms |
14672 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
172 ms |
41316 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 |
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 |
366 ms |
68184 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
1 ms |
860 KB |
Output is correct |
28 |
Correct |
122 ms |
27992 KB |
Output is correct |
29 |
Correct |
184 ms |
40280 KB |
Output is correct |
30 |
Correct |
264 ms |
55120 KB |
Output is correct |
31 |
Correct |
367 ms |
67220 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 |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 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 |
1 ms |
860 KB |
Output is correct |
44 |
Correct |
1 ms |
860 KB |
Output is correct |
45 |
Correct |
163 ms |
38548 KB |
Output is correct |
46 |
Correct |
270 ms |
56660 KB |
Output is correct |
47 |
Correct |
240 ms |
56140 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 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 |
404 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Incorrect |
327 ms |
62680 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
400 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 |
191 ms |
45820 KB |
Output is correct |
10 |
Correct |
12 ms |
5208 KB |
Output is correct |
11 |
Correct |
92 ms |
25176 KB |
Output is correct |
12 |
Correct |
22 ms |
7516 KB |
Output is correct |
13 |
Correct |
40 ms |
14672 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
172 ms |
41316 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 |
373 ms |
80520 KB |
Output is correct |
21 |
Correct |
350 ms |
76028 KB |
Output is correct |
22 |
Correct |
344 ms |
73448 KB |
Output is correct |
23 |
Correct |
280 ms |
72560 KB |
Output is correct |
24 |
Correct |
87 ms |
18380 KB |
Output is correct |
25 |
Correct |
81 ms |
18400 KB |
Output is correct |
26 |
Correct |
74 ms |
18260 KB |
Output is correct |
27 |
Correct |
272 ms |
58856 KB |
Output is correct |
28 |
Correct |
274 ms |
58744 KB |
Output is correct |
29 |
Correct |
400 ms |
58796 KB |
Output is correct |
30 |
Correct |
401 ms |
58704 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
19 ms |
5492 KB |
Output is correct |
33 |
Correct |
36 ms |
9276 KB |
Output is correct |
34 |
Correct |
337 ms |
76916 KB |
Output is correct |
35 |
Correct |
9 ms |
1880 KB |
Output is correct |
36 |
Correct |
25 ms |
6176 KB |
Output is correct |
37 |
Correct |
43 ms |
10568 KB |
Output is correct |
38 |
Correct |
115 ms |
22252 KB |
Output is correct |
39 |
Correct |
176 ms |
30252 KB |
Output is correct |
40 |
Correct |
220 ms |
38764 KB |
Output is correct |
41 |
Correct |
281 ms |
47016 KB |
Output is correct |
42 |
Correct |
345 ms |
55024 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
1 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 |
1 ms |
860 KB |
Output is correct |
55 |
Correct |
2 ms |
860 KB |
Output is correct |
56 |
Correct |
158 ms |
38464 KB |
Output is correct |
57 |
Correct |
234 ms |
56652 KB |
Output is correct |
58 |
Correct |
242 ms |
56136 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
348 KB |
Output is correct |
62 |
Correct |
370 ms |
80468 KB |
Output is correct |
63 |
Correct |
388 ms |
80716 KB |
Output is correct |
64 |
Correct |
364 ms |
82756 KB |
Output is correct |
65 |
Correct |
2 ms |
1116 KB |
Output is correct |
66 |
Correct |
4 ms |
1372 KB |
Output is correct |
67 |
Correct |
155 ms |
34172 KB |
Output is correct |
68 |
Correct |
246 ms |
53828 KB |
Output is correct |
69 |
Correct |
388 ms |
67920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
400 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 |
191 ms |
45820 KB |
Output is correct |
10 |
Correct |
12 ms |
5208 KB |
Output is correct |
11 |
Correct |
92 ms |
25176 KB |
Output is correct |
12 |
Correct |
22 ms |
7516 KB |
Output is correct |
13 |
Correct |
40 ms |
14672 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
172 ms |
41316 KB |
Output is correct |
17 |
Incorrect |
335 ms |
86724 KB |
Solution announced impossible, but it is possible. |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
400 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 |
191 ms |
45820 KB |
Output is correct |
10 |
Correct |
12 ms |
5208 KB |
Output is correct |
11 |
Correct |
92 ms |
25176 KB |
Output is correct |
12 |
Correct |
22 ms |
7516 KB |
Output is correct |
13 |
Correct |
40 ms |
14672 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
172 ms |
41316 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 |
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 |
366 ms |
68184 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
860 KB |
Output is correct |
26 |
Correct |
2 ms |
860 KB |
Output is correct |
27 |
Correct |
1 ms |
860 KB |
Output is correct |
28 |
Correct |
122 ms |
27992 KB |
Output is correct |
29 |
Correct |
184 ms |
40280 KB |
Output is correct |
30 |
Correct |
264 ms |
55120 KB |
Output is correct |
31 |
Correct |
367 ms |
67220 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 |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
344 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 |
1 ms |
860 KB |
Output is correct |
44 |
Correct |
1 ms |
860 KB |
Output is correct |
45 |
Correct |
163 ms |
38548 KB |
Output is correct |
46 |
Correct |
270 ms |
56660 KB |
Output is correct |
47 |
Correct |
240 ms |
56140 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 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 |
404 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Incorrect |
327 ms |
62680 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |