#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(a) a.begin(),a.end()
#define fi first
#define se second
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
const ll inf=1001001001001001001;
struct UF{
ll n;
vi par,sz;
UF(ll n_):n(n_),par(n,-1),sz(n,1){}
void merge(ll a,ll b){
a=root(a);b=root(b);
if(a==b)return;
if(sz[a]>sz[b])swap(a,b);
par[a]=b;
sz[b]+=sz[a];
}
ll root(ll i){
if(par[i]==-1)return i;
par[i]=root(par[i]);
return par[i];
}
bool same(ll a,ll b){
return root(a)==root(b);
}
ll getsz(ll i){
return sz[root(i)];
}
};
int construct_roads(std::vector<int> x, std::vector<int> y) {
ll n=x.size();
UF uf(n);
vector<PP> v(n);
rep(i,n)v[i]=PP(x[i],y[i],i);
sort(all(v));
vi dx={2,0},dy={0,2};
set<P> S;
vector<int> U, V, A, B;
rep(i,n)rep(j,2){
P a(x[i],y[i]),b(x[i]+dx[j],y[i]+dy[j]);
ll l=lb(v,PP(b.fi,b.se,-1));
if(l==n)continue;
l=get<2>(v[l]);
if(P(x[l],y[l])!=b)continue;
P c((a.fi+b.fi)/2,(a.se+b.se)/2);
if(a.fi==b.fi){
if((a.fi+a.se)%4==0)c.fi--;
else c.fi++;
}
else{
if((a.fi+a.se)%4==0)c.se++;
else c.se--;
}
if(S.insert(c).se){
uf.merge(i,l);
U.pb(i);
V.pb(l);
A.pb(c.fi);
B.pb(c.se);
}
}
if(uf.getsz(0)<n)return 0;
build(U,V,A,B);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
109 ms |
17580 KB |
Output is correct |
10 |
Correct |
8 ms |
2004 KB |
Output is correct |
11 |
Correct |
36 ms |
9584 KB |
Output is correct |
12 |
Correct |
13 ms |
2832 KB |
Output is correct |
13 |
Correct |
19 ms |
6464 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
110 ms |
17524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
109 ms |
17580 KB |
Output is correct |
10 |
Correct |
8 ms |
2004 KB |
Output is correct |
11 |
Correct |
36 ms |
9584 KB |
Output is correct |
12 |
Correct |
13 ms |
2832 KB |
Output is correct |
13 |
Correct |
19 ms |
6464 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
110 ms |
17524 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
300 KB |
Output is correct |
23 |
Correct |
333 ms |
33992 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
3 ms |
880 KB |
Output is correct |
28 |
Correct |
94 ms |
14128 KB |
Output is correct |
29 |
Correct |
183 ms |
20856 KB |
Output is correct |
30 |
Correct |
297 ms |
27504 KB |
Output is correct |
31 |
Correct |
380 ms |
34048 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
300 KB |
Output is correct |
43 |
Correct |
2 ms |
564 KB |
Output is correct |
44 |
Correct |
2 ms |
724 KB |
Output is correct |
45 |
Correct |
132 ms |
17536 KB |
Output is correct |
46 |
Correct |
259 ms |
24932 KB |
Output is correct |
47 |
Correct |
181 ms |
25020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
109 ms |
17580 KB |
Output is correct |
10 |
Correct |
8 ms |
2004 KB |
Output is correct |
11 |
Correct |
36 ms |
9584 KB |
Output is correct |
12 |
Correct |
13 ms |
2832 KB |
Output is correct |
13 |
Correct |
19 ms |
6464 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
110 ms |
17524 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
300 KB |
Output is correct |
23 |
Correct |
333 ms |
33992 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
3 ms |
880 KB |
Output is correct |
28 |
Correct |
94 ms |
14128 KB |
Output is correct |
29 |
Correct |
183 ms |
20856 KB |
Output is correct |
30 |
Correct |
297 ms |
27504 KB |
Output is correct |
31 |
Correct |
380 ms |
34048 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
300 KB |
Output is correct |
43 |
Correct |
2 ms |
564 KB |
Output is correct |
44 |
Correct |
2 ms |
724 KB |
Output is correct |
45 |
Correct |
132 ms |
17536 KB |
Output is correct |
46 |
Correct |
259 ms |
24932 KB |
Output is correct |
47 |
Correct |
181 ms |
25020 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
292 KB |
Output is correct |
51 |
Correct |
1 ms |
296 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
288 KB |
Output is correct |
55 |
Incorrect |
352 ms |
28460 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
109 ms |
17580 KB |
Output is correct |
10 |
Correct |
8 ms |
2004 KB |
Output is correct |
11 |
Correct |
36 ms |
9584 KB |
Output is correct |
12 |
Correct |
13 ms |
2832 KB |
Output is correct |
13 |
Correct |
19 ms |
6464 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
110 ms |
17524 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
268 ms |
34464 KB |
Output is correct |
21 |
Correct |
323 ms |
34504 KB |
Output is correct |
22 |
Correct |
277 ms |
34464 KB |
Output is correct |
23 |
Correct |
273 ms |
29500 KB |
Output is correct |
24 |
Correct |
97 ms |
12620 KB |
Output is correct |
25 |
Correct |
284 ms |
28256 KB |
Output is correct |
26 |
Correct |
248 ms |
28196 KB |
Output is correct |
27 |
Correct |
292 ms |
34492 KB |
Output is correct |
28 |
Correct |
306 ms |
34392 KB |
Output is correct |
29 |
Correct |
320 ms |
34420 KB |
Output is correct |
30 |
Correct |
319 ms |
34432 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
15 ms |
2764 KB |
Output is correct |
33 |
Correct |
46 ms |
6992 KB |
Output is correct |
34 |
Correct |
314 ms |
34548 KB |
Output is correct |
35 |
Correct |
8 ms |
1748 KB |
Output is correct |
36 |
Correct |
46 ms |
7480 KB |
Output is correct |
37 |
Correct |
97 ms |
14860 KB |
Output is correct |
38 |
Correct |
94 ms |
14588 KB |
Output is correct |
39 |
Correct |
136 ms |
19616 KB |
Output is correct |
40 |
Correct |
206 ms |
24548 KB |
Output is correct |
41 |
Correct |
262 ms |
29580 KB |
Output is correct |
42 |
Correct |
312 ms |
34464 KB |
Output is correct |
43 |
Correct |
0 ms |
304 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
300 KB |
Output is correct |
54 |
Correct |
2 ms |
468 KB |
Output is correct |
55 |
Correct |
2 ms |
724 KB |
Output is correct |
56 |
Correct |
124 ms |
17876 KB |
Output is correct |
57 |
Correct |
187 ms |
25384 KB |
Output is correct |
58 |
Correct |
200 ms |
25376 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
292 KB |
Output is correct |
61 |
Correct |
0 ms |
212 KB |
Output is correct |
62 |
Correct |
282 ms |
34396 KB |
Output is correct |
63 |
Correct |
278 ms |
34432 KB |
Output is correct |
64 |
Correct |
296 ms |
34412 KB |
Output is correct |
65 |
Correct |
3 ms |
852 KB |
Output is correct |
66 |
Correct |
5 ms |
1336 KB |
Output is correct |
67 |
Correct |
116 ms |
17452 KB |
Output is correct |
68 |
Correct |
217 ms |
26148 KB |
Output is correct |
69 |
Correct |
307 ms |
34372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
109 ms |
17580 KB |
Output is correct |
10 |
Correct |
8 ms |
2004 KB |
Output is correct |
11 |
Correct |
36 ms |
9584 KB |
Output is correct |
12 |
Correct |
13 ms |
2832 KB |
Output is correct |
13 |
Correct |
19 ms |
6464 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
110 ms |
17524 KB |
Output is correct |
17 |
Correct |
298 ms |
34600 KB |
Output is correct |
18 |
Correct |
317 ms |
34224 KB |
Output is correct |
19 |
Correct |
319 ms |
34128 KB |
Output is correct |
20 |
Correct |
403 ms |
40628 KB |
Output is correct |
21 |
Correct |
277 ms |
32204 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
35 ms |
6176 KB |
Output is correct |
24 |
Correct |
17 ms |
3500 KB |
Output is correct |
25 |
Correct |
67 ms |
11540 KB |
Output is correct |
26 |
Correct |
135 ms |
18976 KB |
Output is correct |
27 |
Correct |
155 ms |
19788 KB |
Output is correct |
28 |
Correct |
198 ms |
24596 KB |
Output is correct |
29 |
Correct |
264 ms |
29276 KB |
Output is correct |
30 |
Correct |
289 ms |
33776 KB |
Output is correct |
31 |
Correct |
377 ms |
38488 KB |
Output is correct |
32 |
Correct |
355 ms |
38568 KB |
Output is correct |
33 |
Correct |
311 ms |
34168 KB |
Output is correct |
34 |
Correct |
4 ms |
980 KB |
Output is correct |
35 |
Correct |
6 ms |
1580 KB |
Output is correct |
36 |
Correct |
134 ms |
18552 KB |
Output is correct |
37 |
Correct |
219 ms |
27684 KB |
Output is correct |
38 |
Correct |
322 ms |
36512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
109 ms |
17580 KB |
Output is correct |
10 |
Correct |
8 ms |
2004 KB |
Output is correct |
11 |
Correct |
36 ms |
9584 KB |
Output is correct |
12 |
Correct |
13 ms |
2832 KB |
Output is correct |
13 |
Correct |
19 ms |
6464 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
588 KB |
Output is correct |
16 |
Correct |
110 ms |
17524 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
300 KB |
Output is correct |
23 |
Correct |
333 ms |
33992 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
724 KB |
Output is correct |
27 |
Correct |
3 ms |
880 KB |
Output is correct |
28 |
Correct |
94 ms |
14128 KB |
Output is correct |
29 |
Correct |
183 ms |
20856 KB |
Output is correct |
30 |
Correct |
297 ms |
27504 KB |
Output is correct |
31 |
Correct |
380 ms |
34048 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
300 KB |
Output is correct |
43 |
Correct |
2 ms |
564 KB |
Output is correct |
44 |
Correct |
2 ms |
724 KB |
Output is correct |
45 |
Correct |
132 ms |
17536 KB |
Output is correct |
46 |
Correct |
259 ms |
24932 KB |
Output is correct |
47 |
Correct |
181 ms |
25020 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
292 KB |
Output is correct |
51 |
Correct |
1 ms |
296 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
288 KB |
Output is correct |
55 |
Incorrect |
352 ms |
28460 KB |
Solution announced impossible, but it is possible. |
56 |
Halted |
0 ms |
0 KB |
- |