#include "parks.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef pair<int,int> pii;
map<pii,int> ind;
map<pii,int> ocup;
map<pii,int> match;
struct point
{
int x,y;
} v[200005];
int k;
vector<int> myy[200005];
vector<int> muchii[200005];
bool have[11][200005];
bool use[200005];
void dfs(int nod)
{
use[nod]=1;
for(int i:muchii[nod])
if(!use[i])
dfs(i);
}
int c[11][200005];
vector<int> U,V,A,B;
void addedge(int xa,int ya,int xb,int yb,int xc,int yc)
{
int a=ind[{xa,ya}];
int b=ind[{xb,yb}];
U.push_back(a);
V.push_back(b);
muchii[a].push_back(b);
muchii[b].push_back(a);
A.push_back(xc);
B.push_back(yc);
}
int construct_roads(std::vector<int> X, std::vector<int> Y)
{
k=X.size();
int xmax=0;
for(int i=0;i<k;i++)
{
v[i]={X[i],Y[i]};
ind[{X[i],Y[i]}]=i;
xmax=max(xmax,X[i]);
myy[X[i]].push_back(Y[i]);
have[X[i]][Y[i]]=1;
}
if(xmax<=2)
{
sort(myy[2].begin(),myy[2].end());
vector<int> U,V,a,b;
for(int i=1;i<myy[2].size();i++)
{
if(myy[2][i]-myy[2][i-1]!=2)
return 0;
int x=2;
int yu=myy[2][i-1];
int yv=myy[2][i];
U.push_back(ind[{x,yu}]);
V.push_back(ind[{x,yv}]);
a.push_back(x-1);
b.push_back(yv-1);
}
build(U,V,a,b);
return 1;
}
if(xmax<=4)
{
sort(myy[2].begin(),myy[2].end());
sort(myy[4].begin(),myy[4].end());
vector<int> U,V,A,B;
for(int i=2;i<=200000;i+=2)
if(have[2][i]&&have[2][i-2])
{
int a=ind[{2,i}];
int b=ind[{2,i-2}];
U.push_back(a);
V.push_back(b);
muchii[a].push_back(b);
muchii[b].push_back(a);
A.push_back(1);
B.push_back(i-1);
}
for(int i=2;i<=200000;i+=2)
if(have[4][i]&&have[4][i-2])
{
int a=ind[{4,i}];
int b=ind[{4,i-2}];
U.push_back(a);
V.push_back(b);
muchii[a].push_back(b);
muchii[b].push_back(a);
A.push_back(5);
B.push_back(i-1);
}
for(int i=2;i<=200000;i+=2)
if(have[2][i]&&have[4][i])
{
int a=ind[{2,i}];
int b=ind[{4,i}];
U.push_back(a);
V.push_back(b);
muchii[a].push_back(b);
muchii[b].push_back(a);
A.push_back(3);
B.push_back(i+1);
}
dfs(0);
for(int i=0;i<k;i++)
if(!use[i])
return 0;
build(U,V,A,B);
return 1;
}
if(xmax<=6)
{
sort(myy[2].begin(),myy[2].end());
sort(myy[4].begin(),myy[4].end());
sort(myy[6].begin(),myy[6].end());
int nr=0;
for(int i=2;i<=200000;i+=2)
if(have[2][i])
{
if(have[2][i-2])
{
addedge(2,i,2,i-2,1,i-1);
c[2][i]=c[2][i-2];
}
else
{
nr++;
c[2][i]=nr;
}
}
for(int i=2;i<=200000;i+=2)
if(have[6][i])
{
if(have[6][i-2])
{
addedge(6,i,6,i-2,7,i-1);
c[6][i]=c[6][i-2];
}
else
{
nr++;
c[6][i]=nr;
}
}
int lft=1;
for(int i=2;i<=200000;i+=2)
if(have[4][i])
{
if(have[4][i-2])
{
if(lft==1)
{
addedge(4,i,4,i-2,3,i-1);
ocup[{3,i-1}]=1;
}
else
{
addedge(4,i,4,i-2,5,i-1);
ocup[{5,i-1}]=1;
}
lft^=1;
c[4][i]=c[4][i-2];
}
else
{
lft=1;
nr++;
c[4][i]=nr;
}
}
for(int i=2;i<=200000;i+=2)
if(have[2][i]&&have[4][i])
{
int a=c[2][i];
int b=c[4][i];
if(match[{a,b}]==0)
{
match[{a,b}]=1;
if(!ocup[{3,i-1}])
{
addedge(2,i,4,i,3,i-1);
ocup[{3,i-1}]=1;
}
else
{
addedge(2,i,4,i,3,i+1);
ocup[{3,i+1}]=1;
}
}
}
for(int i=2;i<=200000;i+=2)
if(have[4][i]&&have[6][i])
{
int a=c[4][i];
int b=c[6][i];
if(match[{a,b}]==0)
{
match[{a,b}]=1;
if(!ocup[{5,i-1}])
{
addedge(4,i,6,i,5,i-1);
ocup[{5,i-1}]=1;
}
else
{
addedge(4,i,6,i,5,i+1);
ocup[{5,i+1}]=1;
}
}
}
dfs(0);
for(int i=0;i<k;i++)
if(!use[i])
return 0;
build(U,V,A,B);
return 1;
}
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i=1;i<myy[2].size();i++)
| ~^~~~~~~~~~~~~~
parks.cpp:225:1: warning: control reaches end of non-void function [-Wreturn-type]
225 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9644 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9728 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
4 ms |
9684 KB |
Output is correct |
6 |
Correct |
4 ms |
9684 KB |
Output is correct |
7 |
Correct |
4 ms |
9684 KB |
Output is correct |
8 |
Correct |
4 ms |
9616 KB |
Output is correct |
9 |
Correct |
93 ms |
23864 KB |
Output is correct |
10 |
Correct |
11 ms |
11348 KB |
Output is correct |
11 |
Correct |
46 ms |
17380 KB |
Output is correct |
12 |
Correct |
19 ms |
12012 KB |
Output is correct |
13 |
Correct |
23 ms |
14528 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9812 KB |
Output is correct |
16 |
Correct |
115 ms |
23928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9644 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9728 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
4 ms |
9684 KB |
Output is correct |
6 |
Correct |
4 ms |
9684 KB |
Output is correct |
7 |
Correct |
4 ms |
9684 KB |
Output is correct |
8 |
Correct |
4 ms |
9616 KB |
Output is correct |
9 |
Correct |
93 ms |
23864 KB |
Output is correct |
10 |
Correct |
11 ms |
11348 KB |
Output is correct |
11 |
Correct |
46 ms |
17380 KB |
Output is correct |
12 |
Correct |
19 ms |
12012 KB |
Output is correct |
13 |
Correct |
23 ms |
14528 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9812 KB |
Output is correct |
16 |
Correct |
115 ms |
23928 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
5 ms |
9684 KB |
Output is correct |
22 |
Correct |
6 ms |
9684 KB |
Output is correct |
23 |
Correct |
389 ms |
52068 KB |
Output is correct |
24 |
Correct |
4 ms |
9684 KB |
Output is correct |
25 |
Correct |
8 ms |
9940 KB |
Output is correct |
26 |
Correct |
6 ms |
10224 KB |
Output is correct |
27 |
Correct |
8 ms |
10384 KB |
Output is correct |
28 |
Correct |
103 ms |
26692 KB |
Output is correct |
29 |
Correct |
180 ms |
35140 KB |
Output is correct |
30 |
Correct |
274 ms |
43632 KB |
Output is correct |
31 |
Correct |
305 ms |
52128 KB |
Output is correct |
32 |
Correct |
5 ms |
9684 KB |
Output is correct |
33 |
Correct |
4 ms |
9684 KB |
Output is correct |
34 |
Correct |
4 ms |
9620 KB |
Output is correct |
35 |
Correct |
6 ms |
9684 KB |
Output is correct |
36 |
Correct |
5 ms |
9684 KB |
Output is correct |
37 |
Correct |
5 ms |
9600 KB |
Output is correct |
38 |
Correct |
5 ms |
9684 KB |
Output is correct |
39 |
Correct |
4 ms |
9684 KB |
Output is correct |
40 |
Correct |
4 ms |
9684 KB |
Output is correct |
41 |
Correct |
4 ms |
9684 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
6 ms |
9940 KB |
Output is correct |
44 |
Correct |
7 ms |
10140 KB |
Output is correct |
45 |
Correct |
116 ms |
27960 KB |
Output is correct |
46 |
Correct |
176 ms |
36504 KB |
Output is correct |
47 |
Correct |
218 ms |
36412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9644 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9728 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
4 ms |
9684 KB |
Output is correct |
6 |
Correct |
4 ms |
9684 KB |
Output is correct |
7 |
Correct |
4 ms |
9684 KB |
Output is correct |
8 |
Correct |
4 ms |
9616 KB |
Output is correct |
9 |
Correct |
93 ms |
23864 KB |
Output is correct |
10 |
Correct |
11 ms |
11348 KB |
Output is correct |
11 |
Correct |
46 ms |
17380 KB |
Output is correct |
12 |
Correct |
19 ms |
12012 KB |
Output is correct |
13 |
Correct |
23 ms |
14528 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9812 KB |
Output is correct |
16 |
Correct |
115 ms |
23928 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
5 ms |
9684 KB |
Output is correct |
22 |
Correct |
6 ms |
9684 KB |
Output is correct |
23 |
Correct |
389 ms |
52068 KB |
Output is correct |
24 |
Correct |
4 ms |
9684 KB |
Output is correct |
25 |
Correct |
8 ms |
9940 KB |
Output is correct |
26 |
Correct |
6 ms |
10224 KB |
Output is correct |
27 |
Correct |
8 ms |
10384 KB |
Output is correct |
28 |
Correct |
103 ms |
26692 KB |
Output is correct |
29 |
Correct |
180 ms |
35140 KB |
Output is correct |
30 |
Correct |
274 ms |
43632 KB |
Output is correct |
31 |
Correct |
305 ms |
52128 KB |
Output is correct |
32 |
Correct |
5 ms |
9684 KB |
Output is correct |
33 |
Correct |
4 ms |
9684 KB |
Output is correct |
34 |
Correct |
4 ms |
9620 KB |
Output is correct |
35 |
Correct |
6 ms |
9684 KB |
Output is correct |
36 |
Correct |
5 ms |
9684 KB |
Output is correct |
37 |
Correct |
5 ms |
9600 KB |
Output is correct |
38 |
Correct |
5 ms |
9684 KB |
Output is correct |
39 |
Correct |
4 ms |
9684 KB |
Output is correct |
40 |
Correct |
4 ms |
9684 KB |
Output is correct |
41 |
Correct |
4 ms |
9684 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
6 ms |
9940 KB |
Output is correct |
44 |
Correct |
7 ms |
10140 KB |
Output is correct |
45 |
Correct |
116 ms |
27960 KB |
Output is correct |
46 |
Correct |
176 ms |
36504 KB |
Output is correct |
47 |
Correct |
218 ms |
36412 KB |
Output is correct |
48 |
Correct |
5 ms |
9684 KB |
Output is correct |
49 |
Correct |
5 ms |
9684 KB |
Output is correct |
50 |
Correct |
5 ms |
9684 KB |
Output is correct |
51 |
Correct |
5 ms |
9684 KB |
Output is correct |
52 |
Correct |
5 ms |
9684 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9704 KB |
Output is correct |
55 |
Correct |
271 ms |
53340 KB |
Output is correct |
56 |
Correct |
5 ms |
9708 KB |
Output is correct |
57 |
Correct |
7 ms |
10108 KB |
Output is correct |
58 |
Correct |
10 ms |
11092 KB |
Output is correct |
59 |
Correct |
11 ms |
11660 KB |
Output is correct |
60 |
Correct |
113 ms |
31048 KB |
Output is correct |
61 |
Correct |
166 ms |
40028 KB |
Output is correct |
62 |
Correct |
208 ms |
45828 KB |
Output is correct |
63 |
Correct |
270 ms |
53056 KB |
Output is correct |
64 |
Correct |
5 ms |
9708 KB |
Output is correct |
65 |
Correct |
5 ms |
9748 KB |
Output is correct |
66 |
Correct |
5 ms |
9684 KB |
Output is correct |
67 |
Correct |
242 ms |
49696 KB |
Output is correct |
68 |
Correct |
241 ms |
49760 KB |
Output is correct |
69 |
Correct |
266 ms |
49972 KB |
Output is correct |
70 |
Correct |
8 ms |
10580 KB |
Output is correct |
71 |
Correct |
11 ms |
11500 KB |
Output is correct |
72 |
Correct |
134 ms |
34872 KB |
Output is correct |
73 |
Correct |
229 ms |
48008 KB |
Output is correct |
74 |
Correct |
320 ms |
60132 KB |
Output is correct |
75 |
Correct |
343 ms |
62256 KB |
Output is correct |
76 |
Correct |
243 ms |
50736 KB |
Output is correct |
77 |
Correct |
9 ms |
10804 KB |
Output is correct |
78 |
Correct |
12 ms |
11896 KB |
Output is correct |
79 |
Correct |
155 ms |
35736 KB |
Output is correct |
80 |
Correct |
248 ms |
49052 KB |
Output is correct |
81 |
Correct |
355 ms |
62112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9644 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9728 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
4 ms |
9684 KB |
Output is correct |
6 |
Correct |
4 ms |
9684 KB |
Output is correct |
7 |
Correct |
4 ms |
9684 KB |
Output is correct |
8 |
Correct |
4 ms |
9616 KB |
Output is correct |
9 |
Correct |
93 ms |
23864 KB |
Output is correct |
10 |
Correct |
11 ms |
11348 KB |
Output is correct |
11 |
Correct |
46 ms |
17380 KB |
Output is correct |
12 |
Correct |
19 ms |
12012 KB |
Output is correct |
13 |
Correct |
23 ms |
14528 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9812 KB |
Output is correct |
16 |
Correct |
115 ms |
23928 KB |
Output is correct |
17 |
Runtime error |
12 ms |
19452 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9644 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9728 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
4 ms |
9684 KB |
Output is correct |
6 |
Correct |
4 ms |
9684 KB |
Output is correct |
7 |
Correct |
4 ms |
9684 KB |
Output is correct |
8 |
Correct |
4 ms |
9616 KB |
Output is correct |
9 |
Correct |
93 ms |
23864 KB |
Output is correct |
10 |
Correct |
11 ms |
11348 KB |
Output is correct |
11 |
Correct |
46 ms |
17380 KB |
Output is correct |
12 |
Correct |
19 ms |
12012 KB |
Output is correct |
13 |
Correct |
23 ms |
14528 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9812 KB |
Output is correct |
16 |
Correct |
115 ms |
23928 KB |
Output is correct |
17 |
Runtime error |
42 ms |
25748 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9644 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9728 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
4 ms |
9684 KB |
Output is correct |
6 |
Correct |
4 ms |
9684 KB |
Output is correct |
7 |
Correct |
4 ms |
9684 KB |
Output is correct |
8 |
Correct |
4 ms |
9616 KB |
Output is correct |
9 |
Correct |
93 ms |
23864 KB |
Output is correct |
10 |
Correct |
11 ms |
11348 KB |
Output is correct |
11 |
Correct |
46 ms |
17380 KB |
Output is correct |
12 |
Correct |
19 ms |
12012 KB |
Output is correct |
13 |
Correct |
23 ms |
14528 KB |
Output is correct |
14 |
Correct |
6 ms |
9812 KB |
Output is correct |
15 |
Correct |
5 ms |
9812 KB |
Output is correct |
16 |
Correct |
115 ms |
23928 KB |
Output is correct |
17 |
Correct |
5 ms |
9684 KB |
Output is correct |
18 |
Correct |
5 ms |
9684 KB |
Output is correct |
19 |
Correct |
5 ms |
9684 KB |
Output is correct |
20 |
Correct |
5 ms |
9684 KB |
Output is correct |
21 |
Correct |
5 ms |
9684 KB |
Output is correct |
22 |
Correct |
6 ms |
9684 KB |
Output is correct |
23 |
Correct |
389 ms |
52068 KB |
Output is correct |
24 |
Correct |
4 ms |
9684 KB |
Output is correct |
25 |
Correct |
8 ms |
9940 KB |
Output is correct |
26 |
Correct |
6 ms |
10224 KB |
Output is correct |
27 |
Correct |
8 ms |
10384 KB |
Output is correct |
28 |
Correct |
103 ms |
26692 KB |
Output is correct |
29 |
Correct |
180 ms |
35140 KB |
Output is correct |
30 |
Correct |
274 ms |
43632 KB |
Output is correct |
31 |
Correct |
305 ms |
52128 KB |
Output is correct |
32 |
Correct |
5 ms |
9684 KB |
Output is correct |
33 |
Correct |
4 ms |
9684 KB |
Output is correct |
34 |
Correct |
4 ms |
9620 KB |
Output is correct |
35 |
Correct |
6 ms |
9684 KB |
Output is correct |
36 |
Correct |
5 ms |
9684 KB |
Output is correct |
37 |
Correct |
5 ms |
9600 KB |
Output is correct |
38 |
Correct |
5 ms |
9684 KB |
Output is correct |
39 |
Correct |
4 ms |
9684 KB |
Output is correct |
40 |
Correct |
4 ms |
9684 KB |
Output is correct |
41 |
Correct |
4 ms |
9684 KB |
Output is correct |
42 |
Correct |
5 ms |
9684 KB |
Output is correct |
43 |
Correct |
6 ms |
9940 KB |
Output is correct |
44 |
Correct |
7 ms |
10140 KB |
Output is correct |
45 |
Correct |
116 ms |
27960 KB |
Output is correct |
46 |
Correct |
176 ms |
36504 KB |
Output is correct |
47 |
Correct |
218 ms |
36412 KB |
Output is correct |
48 |
Correct |
5 ms |
9684 KB |
Output is correct |
49 |
Correct |
5 ms |
9684 KB |
Output is correct |
50 |
Correct |
5 ms |
9684 KB |
Output is correct |
51 |
Correct |
5 ms |
9684 KB |
Output is correct |
52 |
Correct |
5 ms |
9684 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
5 ms |
9704 KB |
Output is correct |
55 |
Correct |
271 ms |
53340 KB |
Output is correct |
56 |
Correct |
5 ms |
9708 KB |
Output is correct |
57 |
Correct |
7 ms |
10108 KB |
Output is correct |
58 |
Correct |
10 ms |
11092 KB |
Output is correct |
59 |
Correct |
11 ms |
11660 KB |
Output is correct |
60 |
Correct |
113 ms |
31048 KB |
Output is correct |
61 |
Correct |
166 ms |
40028 KB |
Output is correct |
62 |
Correct |
208 ms |
45828 KB |
Output is correct |
63 |
Correct |
270 ms |
53056 KB |
Output is correct |
64 |
Correct |
5 ms |
9708 KB |
Output is correct |
65 |
Correct |
5 ms |
9748 KB |
Output is correct |
66 |
Correct |
5 ms |
9684 KB |
Output is correct |
67 |
Correct |
242 ms |
49696 KB |
Output is correct |
68 |
Correct |
241 ms |
49760 KB |
Output is correct |
69 |
Correct |
266 ms |
49972 KB |
Output is correct |
70 |
Correct |
8 ms |
10580 KB |
Output is correct |
71 |
Correct |
11 ms |
11500 KB |
Output is correct |
72 |
Correct |
134 ms |
34872 KB |
Output is correct |
73 |
Correct |
229 ms |
48008 KB |
Output is correct |
74 |
Correct |
320 ms |
60132 KB |
Output is correct |
75 |
Correct |
343 ms |
62256 KB |
Output is correct |
76 |
Correct |
243 ms |
50736 KB |
Output is correct |
77 |
Correct |
9 ms |
10804 KB |
Output is correct |
78 |
Correct |
12 ms |
11896 KB |
Output is correct |
79 |
Correct |
155 ms |
35736 KB |
Output is correct |
80 |
Correct |
248 ms |
49052 KB |
Output is correct |
81 |
Correct |
355 ms |
62112 KB |
Output is correct |
82 |
Runtime error |
12 ms |
19452 KB |
Execution killed with signal 11 |
83 |
Halted |
0 ms |
0 KB |
- |