#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<bool> vb;
typedef vector<P> vp;
typedef vector<vp> vvp;
#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 fi first
#define se second
#define pb emplace_back
#define all(a) a.begin(),a.end()
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
vi dx={2,0,-2,0},dy={0,2,0,-2};
ll mx=200005;
int construct_roads(std::vector<int> X, std::vector<int> Y) {
if (X.size() == 1) {
build({}, {}, {}, {});
return 1;
}
ll n=X.size();
map<P,ll> mp;
rep(i,n)mp[P(X[i],Y[i])]=i;
vp edge;
rep(i,n)rep(j,2){
ll nx=X[i]+dx[j],ny=Y[i]+dy[j];
if(mp.count(P(nx,ny)))edge.pb(i,mp[P(nx,ny)]);
}
{
vvi g(n);
for(auto x:edge){
g[x.fi].pb(x.se);
g[x.se].pb(x.fi);
}
queue<ll> que;
vb done(n,false);
done[0]=true;
que.push(0);
while(!que.empty()){
ll t=que.front();que.pop();
for(ll x:g[t])if(!done[x]){
done[x]=true;que.push(x);
}
}
rep(i,n)if(!done[i])return 0;
}
vvp al(mx);
rep(i,n)al[Y[i]].pb(X[i],i);
rep(i,mx)sort(all(al[i]));
vector<int> u, v, a, b;
auto add=[&](ll i,ll j,ll t){
u.pb(i);v.pb(j);
if(t==0||t==1){
assert(Y[i]==Y[j]);
a.pb((X[i]+X[j])/2);
if(t==0)b.pb(Y[i]-1);
else b.pb(Y[i]+1);
}
else{
assert(X[i]==X[j]);
b.pb((Y[i]+Y[j])/2);
if(t==2)a.pb(X[i]-1);
else a.pb(X[i]+1);
}
};
bool small=true;
rep(i,n)if(X[i]>6)small=false;
if(small){
vb tmp(2,false);
rep(i,mx)if(al[i].size()){
vb ntmp(2,false);
if(!al[i-2].size()){
rep(j,al[i].size()-1)if(al[i][j+1].fi-al[i][j].fi==2)add(al[i][j].se,al[i][j+1].se,0);
}
else{
if(al[i].back().fi==6&&al[i-2].back().fi==6)add(al[i].back().se,al[i-2].back().se,3);
if(al[i][0].fi==2&&al[i-2][0].fi==2)add(al[i][0].se,al[i-2][0].se,2);
if(al[i][0].fi==4&&al[i-2].back().fi==4){
add(al[i][0].se,al[i-2].back().se,3);
if(al[i].size()>1){
add(al[i][0].se,al[i][1].se,1);
ntmp[1]=true;
}
}
else if(al[i].back().fi==4&&al[i-2][0].fi==4){
add(al[i].back().se,al[i-2][0].se,2);
if(al[i].size()>1){
add(al[i][0].se,al[i][1].se,1);
ntmp[0]=true;
}
}
else if(al[i-2].size()==3&&al[i].size()==1&&al[i][0].fi==4){
if(tmp[1])add(al[i-2][1].se,al[i][0].se,2);
else add(al[i-2][1].se,al[i][0].se,3);
}
else if(al[i-2].size()==1&&al[i-2][0].fi==4&&al[i].size()==3){
add(al[i-2][0].se,al[i][1].se,3);
add(al[i][0].se,al[i][1].se,0);
add(al[i][1].se,al[i][2].se,1);
ntmp[1]=true;
}
else{
rep(j,al[i].size()-1)if(al[i][j+1].fi-al[i][j].fi==2){
ll t=al[i][j].fi/2-1;
if(tmp[t]){
ntmp[t]=true;add(al[i][j].se,al[i][j+1].se,1);
}
else add(al[i][j].se,al[i][j+1].se,0);
}
}
}
tmp=ntmp;
}
build(u, v, a, b);
return 1;
}
for(auto x:edge){
u.pb(x.fi);v.pb(x.se);
P p((X[x.fi]+X[x.se])/2,(Y[x.fi]+Y[x.se])/2);
if(X[x.fi]==X[x.se]){
p.fi++;
if((p.fi+p.se)%4==2)p.fi-=2;
}
else{
p.se++;
if((p.fi+p.se)%4==0)p.se-=2;
}
a.pb(p.fi);b.pb(p.se);
}
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:30:15: warning: control reaches end of non-void function [-Wreturn-type]
30 | map<P,ll> mp;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
185 ms |
22492 KB |
Output is correct |
10 |
Correct |
14 ms |
6764 KB |
Output is correct |
11 |
Correct |
72 ms |
14380 KB |
Output is correct |
12 |
Correct |
20 ms |
7504 KB |
Output is correct |
13 |
Correct |
34 ms |
6864 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
180 ms |
22560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
185 ms |
22492 KB |
Output is correct |
10 |
Correct |
14 ms |
6764 KB |
Output is correct |
11 |
Correct |
72 ms |
14380 KB |
Output is correct |
12 |
Correct |
20 ms |
7504 KB |
Output is correct |
13 |
Correct |
34 ms |
6864 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
180 ms |
22560 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
584 ms |
42208 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
5 ms |
5204 KB |
Output is correct |
26 |
Correct |
4 ms |
852 KB |
Output is correct |
27 |
Correct |
4 ms |
980 KB |
Output is correct |
28 |
Correct |
168 ms |
19868 KB |
Output is correct |
29 |
Correct |
254 ms |
26832 KB |
Output is correct |
30 |
Correct |
436 ms |
35388 KB |
Output is correct |
31 |
Correct |
526 ms |
42156 KB |
Output is correct |
32 |
Correct |
3 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
4 ms |
4948 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
3 ms |
724 KB |
Output is correct |
45 |
Correct |
229 ms |
22488 KB |
Output is correct |
46 |
Correct |
337 ms |
30032 KB |
Output is correct |
47 |
Correct |
299 ms |
30896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
185 ms |
22492 KB |
Output is correct |
10 |
Correct |
14 ms |
6764 KB |
Output is correct |
11 |
Correct |
72 ms |
14380 KB |
Output is correct |
12 |
Correct |
20 ms |
7504 KB |
Output is correct |
13 |
Correct |
34 ms |
6864 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
180 ms |
22560 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
584 ms |
42208 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
5 ms |
5204 KB |
Output is correct |
26 |
Correct |
4 ms |
852 KB |
Output is correct |
27 |
Correct |
4 ms |
980 KB |
Output is correct |
28 |
Correct |
168 ms |
19868 KB |
Output is correct |
29 |
Correct |
254 ms |
26832 KB |
Output is correct |
30 |
Correct |
436 ms |
35388 KB |
Output is correct |
31 |
Correct |
526 ms |
42156 KB |
Output is correct |
32 |
Correct |
3 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
4 ms |
4948 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
3 ms |
724 KB |
Output is correct |
45 |
Correct |
229 ms |
22488 KB |
Output is correct |
46 |
Correct |
337 ms |
30032 KB |
Output is correct |
47 |
Correct |
299 ms |
30896 KB |
Output is correct |
48 |
Correct |
4 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
3 ms |
4892 KB |
Output is correct |
51 |
Correct |
3 ms |
4948 KB |
Output is correct |
52 |
Correct |
3 ms |
4948 KB |
Output is correct |
53 |
Correct |
3 ms |
5000 KB |
Output is correct |
54 |
Correct |
3 ms |
4948 KB |
Output is correct |
55 |
Correct |
627 ms |
49908 KB |
Output is correct |
56 |
Correct |
3 ms |
4948 KB |
Output is correct |
57 |
Correct |
6 ms |
5332 KB |
Output is correct |
58 |
Correct |
13 ms |
6208 KB |
Output is correct |
59 |
Correct |
13 ms |
2004 KB |
Output is correct |
60 |
Correct |
220 ms |
26408 KB |
Output is correct |
61 |
Correct |
373 ms |
33568 KB |
Output is correct |
62 |
Correct |
476 ms |
40032 KB |
Output is correct |
63 |
Correct |
641 ms |
48992 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
3 ms |
4948 KB |
Output is correct |
66 |
Correct |
0 ms |
212 KB |
Output is correct |
67 |
Correct |
486 ms |
40044 KB |
Output is correct |
68 |
Correct |
486 ms |
40048 KB |
Output is correct |
69 |
Correct |
446 ms |
39916 KB |
Output is correct |
70 |
Correct |
4 ms |
852 KB |
Output is correct |
71 |
Correct |
7 ms |
1492 KB |
Output is correct |
72 |
Correct |
221 ms |
22476 KB |
Output is correct |
73 |
Correct |
402 ms |
31720 KB |
Output is correct |
74 |
Correct |
479 ms |
39980 KB |
Output is correct |
75 |
Correct |
539 ms |
43604 KB |
Output is correct |
76 |
Correct |
417 ms |
40036 KB |
Output is correct |
77 |
Correct |
4 ms |
980 KB |
Output is correct |
78 |
Correct |
9 ms |
1716 KB |
Output is correct |
79 |
Correct |
212 ms |
23380 KB |
Output is correct |
80 |
Correct |
450 ms |
32776 KB |
Output is correct |
81 |
Correct |
499 ms |
41320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
185 ms |
22492 KB |
Output is correct |
10 |
Correct |
14 ms |
6764 KB |
Output is correct |
11 |
Correct |
72 ms |
14380 KB |
Output is correct |
12 |
Correct |
20 ms |
7504 KB |
Output is correct |
13 |
Correct |
34 ms |
6864 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
180 ms |
22560 KB |
Output is correct |
17 |
Runtime error |
3 ms |
4948 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
185 ms |
22492 KB |
Output is correct |
10 |
Correct |
14 ms |
6764 KB |
Output is correct |
11 |
Correct |
72 ms |
14380 KB |
Output is correct |
12 |
Correct |
20 ms |
7504 KB |
Output is correct |
13 |
Correct |
34 ms |
6864 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
180 ms |
22560 KB |
Output is correct |
17 |
Runtime error |
394 ms |
45084 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
4948 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
185 ms |
22492 KB |
Output is correct |
10 |
Correct |
14 ms |
6764 KB |
Output is correct |
11 |
Correct |
72 ms |
14380 KB |
Output is correct |
12 |
Correct |
20 ms |
7504 KB |
Output is correct |
13 |
Correct |
34 ms |
6864 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
180 ms |
22560 KB |
Output is correct |
17 |
Correct |
4 ms |
4948 KB |
Output is correct |
18 |
Correct |
4 ms |
4948 KB |
Output is correct |
19 |
Correct |
3 ms |
4948 KB |
Output is correct |
20 |
Correct |
3 ms |
4948 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
4948 KB |
Output is correct |
23 |
Correct |
584 ms |
42208 KB |
Output is correct |
24 |
Correct |
3 ms |
4948 KB |
Output is correct |
25 |
Correct |
5 ms |
5204 KB |
Output is correct |
26 |
Correct |
4 ms |
852 KB |
Output is correct |
27 |
Correct |
4 ms |
980 KB |
Output is correct |
28 |
Correct |
168 ms |
19868 KB |
Output is correct |
29 |
Correct |
254 ms |
26832 KB |
Output is correct |
30 |
Correct |
436 ms |
35388 KB |
Output is correct |
31 |
Correct |
526 ms |
42156 KB |
Output is correct |
32 |
Correct |
3 ms |
4948 KB |
Output is correct |
33 |
Correct |
3 ms |
4948 KB |
Output is correct |
34 |
Correct |
4 ms |
4948 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
3 ms |
4948 KB |
Output is correct |
38 |
Correct |
3 ms |
4948 KB |
Output is correct |
39 |
Correct |
3 ms |
4948 KB |
Output is correct |
40 |
Correct |
3 ms |
4948 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
2 ms |
596 KB |
Output is correct |
44 |
Correct |
3 ms |
724 KB |
Output is correct |
45 |
Correct |
229 ms |
22488 KB |
Output is correct |
46 |
Correct |
337 ms |
30032 KB |
Output is correct |
47 |
Correct |
299 ms |
30896 KB |
Output is correct |
48 |
Correct |
4 ms |
4948 KB |
Output is correct |
49 |
Correct |
3 ms |
4948 KB |
Output is correct |
50 |
Correct |
3 ms |
4892 KB |
Output is correct |
51 |
Correct |
3 ms |
4948 KB |
Output is correct |
52 |
Correct |
3 ms |
4948 KB |
Output is correct |
53 |
Correct |
3 ms |
5000 KB |
Output is correct |
54 |
Correct |
3 ms |
4948 KB |
Output is correct |
55 |
Correct |
627 ms |
49908 KB |
Output is correct |
56 |
Correct |
3 ms |
4948 KB |
Output is correct |
57 |
Correct |
6 ms |
5332 KB |
Output is correct |
58 |
Correct |
13 ms |
6208 KB |
Output is correct |
59 |
Correct |
13 ms |
2004 KB |
Output is correct |
60 |
Correct |
220 ms |
26408 KB |
Output is correct |
61 |
Correct |
373 ms |
33568 KB |
Output is correct |
62 |
Correct |
476 ms |
40032 KB |
Output is correct |
63 |
Correct |
641 ms |
48992 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
3 ms |
4948 KB |
Output is correct |
66 |
Correct |
0 ms |
212 KB |
Output is correct |
67 |
Correct |
486 ms |
40044 KB |
Output is correct |
68 |
Correct |
486 ms |
40048 KB |
Output is correct |
69 |
Correct |
446 ms |
39916 KB |
Output is correct |
70 |
Correct |
4 ms |
852 KB |
Output is correct |
71 |
Correct |
7 ms |
1492 KB |
Output is correct |
72 |
Correct |
221 ms |
22476 KB |
Output is correct |
73 |
Correct |
402 ms |
31720 KB |
Output is correct |
74 |
Correct |
479 ms |
39980 KB |
Output is correct |
75 |
Correct |
539 ms |
43604 KB |
Output is correct |
76 |
Correct |
417 ms |
40036 KB |
Output is correct |
77 |
Correct |
4 ms |
980 KB |
Output is correct |
78 |
Correct |
9 ms |
1716 KB |
Output is correct |
79 |
Correct |
212 ms |
23380 KB |
Output is correct |
80 |
Correct |
450 ms |
32776 KB |
Output is correct |
81 |
Correct |
499 ms |
41320 KB |
Output is correct |
82 |
Runtime error |
3 ms |
4948 KB |
Execution killed with signal 11 |
83 |
Halted |
0 ms |
0 KB |
- |