#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
const int mxn=2e5+100;
int n,color[10][mxn],arr[10][mxn],say,cl[10][mxn];
int l[4]={0,0,2,-2};
int r[4]={2,-2,0,0};
bool qq=true;
vector<int>a,b,c,d;
void bfs(int x,int y){
queue<pii>q;
q.push({x,y});
color[x][y]=1;
while(q.size()){
pii p=q.front();
q.pop();
x=p.F,y=p.S;
say++;
for(int i=0;i<4;i++){
int u=x+l[i],v=y+r[i];
if(arr[u][v]&&!color[u][v]){
a.pb(arr[x][y]-1);
b.pb(arr[u][v]-1);
int q1=x-1,q2=v-1;
if(x!=u){
q1=(x+u)/2;
if(cl[q1][q2]){
q2+=2;
}
}
else{
q2=(y+v)/2;
if(cl[q1][q2]){
q1+=2;
}
}
if(cl[q1][q2]){
qq=false;
}
cl[q1][q2]=1;
c.pb(q1);
d.pb(q2);
q.push({u,v});
color[u][v]=1;
}
}
}
}
void dfs(int x,int y){
color[x][y]=1;
say++;
for(int i=0;i<4;i++){
int u=x+l[i],v=y+r[i];
if(arr[x][y]&&arr[u][v]&&!color[u][v]){
a.pb(arr[x][y]-1);
b.pb(arr[u][v]-1);
int q1=x+1,q2=v+1;
if(x!=u){
q1=(x+u)/2;
if(cl[q1][q2]){
q2-=2;
}
}
else{
q2=(y+v)/2;
if(cl[q1][q2]){
q1-=2;
}
}
if(cl[q1][q2]){
qq=false;
}
cl[q1][q2]=1;
c.pb(q1);
d.pb(q2);
dfs(u,v);
}
}
}
int construct_roads(vector<int> x, vector<int> y) {
n=x.size();
int a1=-1e7,b1=-1e7,a2=1e7,b2=1e7;
for(int i=0;i<n;i++){
a1=max(a1,x[i]);
b1=max(b1,y[i]);
a2=min(a2,x[i]);
b2=min(b2,y[i]);
arr[x[i]][y[i]]=i+1;
}
dfs(a2,b2);
if(say==n){
build(a,b,c,d);
return 1;
}
qq=true;
say=0;
memset(color,0,sizeof(color));
memset(cl,0,sizeof(cl));
a.clear(),b.clear(),c.clear(),d.clear();
dfs(a1,b1);
if(say==n){
build(a,b,c,d);
return 1;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
15924 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15920 KB |
Output is correct |
8 |
Correct |
7 ms |
15872 KB |
Output is correct |
9 |
Correct |
63 ms |
21580 KB |
Output is correct |
10 |
Correct |
6 ms |
2636 KB |
Output is correct |
11 |
Correct |
35 ms |
11888 KB |
Output is correct |
12 |
Correct |
9 ms |
3748 KB |
Output is correct |
13 |
Correct |
17 ms |
21552 KB |
Output is correct |
14 |
Correct |
8 ms |
16008 KB |
Output is correct |
15 |
Correct |
8 ms |
16076 KB |
Output is correct |
16 |
Correct |
56 ms |
21676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
15924 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15920 KB |
Output is correct |
8 |
Correct |
7 ms |
15872 KB |
Output is correct |
9 |
Correct |
63 ms |
21580 KB |
Output is correct |
10 |
Correct |
6 ms |
2636 KB |
Output is correct |
11 |
Correct |
35 ms |
11888 KB |
Output is correct |
12 |
Correct |
9 ms |
3748 KB |
Output is correct |
13 |
Correct |
17 ms |
21552 KB |
Output is correct |
14 |
Correct |
8 ms |
16008 KB |
Output is correct |
15 |
Correct |
8 ms |
16076 KB |
Output is correct |
16 |
Correct |
56 ms |
21676 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
7 ms |
15948 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
119 ms |
42860 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
7 ms |
16204 KB |
Output is correct |
27 |
Correct |
8 ms |
16076 KB |
Output is correct |
28 |
Correct |
50 ms |
17468 KB |
Output is correct |
29 |
Correct |
73 ms |
25984 KB |
Output is correct |
30 |
Correct |
92 ms |
34424 KB |
Output is correct |
31 |
Correct |
120 ms |
42880 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
304 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
7 ms |
15948 KB |
Output is correct |
36 |
Correct |
7 ms |
15948 KB |
Output is correct |
37 |
Correct |
0 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
7 ms |
15980 KB |
Output is correct |
41 |
Correct |
7 ms |
15920 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
8 ms |
16076 KB |
Output is correct |
44 |
Correct |
8 ms |
16028 KB |
Output is correct |
45 |
Incorrect |
60 ms |
33352 KB |
Tree @(3, 62143) appears more than once: for edges on positions 79397 and 79401 |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
15924 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15920 KB |
Output is correct |
8 |
Correct |
7 ms |
15872 KB |
Output is correct |
9 |
Correct |
63 ms |
21580 KB |
Output is correct |
10 |
Correct |
6 ms |
2636 KB |
Output is correct |
11 |
Correct |
35 ms |
11888 KB |
Output is correct |
12 |
Correct |
9 ms |
3748 KB |
Output is correct |
13 |
Correct |
17 ms |
21552 KB |
Output is correct |
14 |
Correct |
8 ms |
16008 KB |
Output is correct |
15 |
Correct |
8 ms |
16076 KB |
Output is correct |
16 |
Correct |
56 ms |
21676 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
7 ms |
15948 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
119 ms |
42860 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
7 ms |
16204 KB |
Output is correct |
27 |
Correct |
8 ms |
16076 KB |
Output is correct |
28 |
Correct |
50 ms |
17468 KB |
Output is correct |
29 |
Correct |
73 ms |
25984 KB |
Output is correct |
30 |
Correct |
92 ms |
34424 KB |
Output is correct |
31 |
Correct |
120 ms |
42880 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
304 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
7 ms |
15948 KB |
Output is correct |
36 |
Correct |
7 ms |
15948 KB |
Output is correct |
37 |
Correct |
0 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
7 ms |
15980 KB |
Output is correct |
41 |
Correct |
7 ms |
15920 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
8 ms |
16076 KB |
Output is correct |
44 |
Correct |
8 ms |
16028 KB |
Output is correct |
45 |
Incorrect |
60 ms |
33352 KB |
Tree @(3, 62143) appears more than once: for edges on positions 79397 and 79401 |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
15924 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15920 KB |
Output is correct |
8 |
Correct |
7 ms |
15872 KB |
Output is correct |
9 |
Correct |
63 ms |
21580 KB |
Output is correct |
10 |
Correct |
6 ms |
2636 KB |
Output is correct |
11 |
Correct |
35 ms |
11888 KB |
Output is correct |
12 |
Correct |
9 ms |
3748 KB |
Output is correct |
13 |
Correct |
17 ms |
21552 KB |
Output is correct |
14 |
Correct |
8 ms |
16008 KB |
Output is correct |
15 |
Correct |
8 ms |
16076 KB |
Output is correct |
16 |
Correct |
56 ms |
21676 KB |
Output is correct |
17 |
Runtime error |
1 ms |
332 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
15924 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15920 KB |
Output is correct |
8 |
Correct |
7 ms |
15872 KB |
Output is correct |
9 |
Correct |
63 ms |
21580 KB |
Output is correct |
10 |
Correct |
6 ms |
2636 KB |
Output is correct |
11 |
Correct |
35 ms |
11888 KB |
Output is correct |
12 |
Correct |
9 ms |
3748 KB |
Output is correct |
13 |
Correct |
17 ms |
21552 KB |
Output is correct |
14 |
Correct |
8 ms |
16008 KB |
Output is correct |
15 |
Correct |
8 ms |
16076 KB |
Output is correct |
16 |
Correct |
56 ms |
21676 KB |
Output is correct |
17 |
Runtime error |
59 ms |
6892 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
15924 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
7 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15920 KB |
Output is correct |
8 |
Correct |
7 ms |
15872 KB |
Output is correct |
9 |
Correct |
63 ms |
21580 KB |
Output is correct |
10 |
Correct |
6 ms |
2636 KB |
Output is correct |
11 |
Correct |
35 ms |
11888 KB |
Output is correct |
12 |
Correct |
9 ms |
3748 KB |
Output is correct |
13 |
Correct |
17 ms |
21552 KB |
Output is correct |
14 |
Correct |
8 ms |
16008 KB |
Output is correct |
15 |
Correct |
8 ms |
16076 KB |
Output is correct |
16 |
Correct |
56 ms |
21676 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
7 ms |
15948 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
119 ms |
42860 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
592 KB |
Output is correct |
26 |
Correct |
7 ms |
16204 KB |
Output is correct |
27 |
Correct |
8 ms |
16076 KB |
Output is correct |
28 |
Correct |
50 ms |
17468 KB |
Output is correct |
29 |
Correct |
73 ms |
25984 KB |
Output is correct |
30 |
Correct |
92 ms |
34424 KB |
Output is correct |
31 |
Correct |
120 ms |
42880 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
304 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
7 ms |
15948 KB |
Output is correct |
36 |
Correct |
7 ms |
15948 KB |
Output is correct |
37 |
Correct |
0 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
7 ms |
15980 KB |
Output is correct |
41 |
Correct |
7 ms |
15920 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
8 ms |
16076 KB |
Output is correct |
44 |
Correct |
8 ms |
16028 KB |
Output is correct |
45 |
Incorrect |
60 ms |
33352 KB |
Tree @(3, 62143) appears more than once: for edges on positions 79397 and 79401 |
46 |
Halted |
0 ms |
0 KB |
- |