#include <iostream>
#include <vector>
using namespace std;
#include "parks.h"
#include <cstdio>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
const int N = 200000 + 10;
int seen[10][N];
int seen2[10][N];
int used[12][N];
int sn = 0;
vector<pair<int,int>> d = {{0,2},{2,0},{-2,0},{0,-2}};
vector<int> a,b,X,Y;
vector<pair<int,int>> up,nup;
void dfs(int i,int j){
seen2[i][j] = true;
sn++;
for (auto [x,y] : d){
int ni = i + x;
int nj = j + y;
if (!seen[ni][nj] or seen2[ni][nj])
continue;
if (i==ni)
up.push_back({seen[i][j]-1,seen[ni][nj]-1});
else
nup.push_back({seen[i][j]-1,seen[ni][nj]-1});
dfs(ni,nj);
}
}
pair<int,int> det(int x1,int y1,int x2,int y2){
if (x1 == x2){
if (y1>y2)
swap(y1,y2);
if (x1 == 2)
return {1,y1+1};
if (x1 == 6)
return {7,y1+1};
if (used[3][y1-1] or used[3][y2 + 1])
return {5,y1 + 1};
return {3,y1 + 1};
}
if (x1>x2)
swap(x1,x2);
if (used[x1+1][y1-1])
return {x1+1,y1+1};
return {x1+1,y1-1};
}
int construct_roads(vector<int> x,vector<int> y){
int n = x.size();
int mny = 1e7,k;
for (int i=0;i<n;i++){
seen[x[i]][y[i]] = i+1;
if (y[i]<mny)
mny = y[i],k = x[i];
}
dfs(k,mny);
if (sn!=n)
return 0;
for (auto [i,j] : up){
auto [ii,jj] = det(x[i],y[i],x[j],y[j]);
used[ii][jj] = true;
a.push_back(i);
b.push_back(j);
X.push_back(ii);
Y.push_back(jj);
}
for (auto [i,j] : nup){
auto [ii,jj] = det(x[i],y[i],x[j],y[j]);
used[ii][jj] = true;
a.push_back(i);
b.push_back(j);
X.push_back(ii);
Y.push_back(jj);
}
build(a,b,X,Y);
return 1;
}
Compilation message
parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:89:5: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
89 | dfs(k,mny);
| ~~~^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4532 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
47 ms |
26796 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
26 ms |
17448 KB |
Output is correct |
12 |
Correct |
10 ms |
9816 KB |
Output is correct |
13 |
Correct |
8 ms |
9176 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
49 ms |
26856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4532 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
47 ms |
26796 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
26 ms |
17448 KB |
Output is correct |
12 |
Correct |
10 ms |
9816 KB |
Output is correct |
13 |
Correct |
8 ms |
9176 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
49 ms |
26856 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
8640 KB |
Output is correct |
23 |
Correct |
101 ms |
53144 KB |
Output is correct |
24 |
Correct |
1 ms |
10584 KB |
Output is correct |
25 |
Correct |
2 ms |
10952 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
1 ms |
6748 KB |
Output is correct |
28 |
Correct |
42 ms |
23780 KB |
Output is correct |
29 |
Correct |
58 ms |
35624 KB |
Output is correct |
30 |
Correct |
79 ms |
45364 KB |
Output is correct |
31 |
Correct |
98 ms |
52924 KB |
Output is correct |
32 |
Correct |
1 ms |
4448 KB |
Output is correct |
33 |
Correct |
1 ms |
4576 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4440 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
8540 KB |
Output is correct |
43 |
Correct |
1 ms |
4700 KB |
Output is correct |
44 |
Correct |
2 ms |
6600 KB |
Output is correct |
45 |
Correct |
51 ms |
30652 KB |
Output is correct |
46 |
Correct |
72 ms |
38220 KB |
Output is correct |
47 |
Correct |
70 ms |
38092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4532 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
47 ms |
26796 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
26 ms |
17448 KB |
Output is correct |
12 |
Correct |
10 ms |
9816 KB |
Output is correct |
13 |
Correct |
8 ms |
9176 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
49 ms |
26856 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
8640 KB |
Output is correct |
23 |
Correct |
101 ms |
53144 KB |
Output is correct |
24 |
Correct |
1 ms |
10584 KB |
Output is correct |
25 |
Correct |
2 ms |
10952 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
1 ms |
6748 KB |
Output is correct |
28 |
Correct |
42 ms |
23780 KB |
Output is correct |
29 |
Correct |
58 ms |
35624 KB |
Output is correct |
30 |
Correct |
79 ms |
45364 KB |
Output is correct |
31 |
Correct |
98 ms |
52924 KB |
Output is correct |
32 |
Correct |
1 ms |
4448 KB |
Output is correct |
33 |
Correct |
1 ms |
4576 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4440 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
8540 KB |
Output is correct |
43 |
Correct |
1 ms |
4700 KB |
Output is correct |
44 |
Correct |
2 ms |
6600 KB |
Output is correct |
45 |
Correct |
51 ms |
30652 KB |
Output is correct |
46 |
Correct |
72 ms |
38220 KB |
Output is correct |
47 |
Correct |
70 ms |
38092 KB |
Output is correct |
48 |
Correct |
1 ms |
8536 KB |
Output is correct |
49 |
Correct |
1 ms |
8540 KB |
Output is correct |
50 |
Correct |
1 ms |
10688 KB |
Output is correct |
51 |
Correct |
2 ms |
10588 KB |
Output is correct |
52 |
Correct |
2 ms |
10588 KB |
Output is correct |
53 |
Correct |
1 ms |
10588 KB |
Output is correct |
54 |
Correct |
1 ms |
10588 KB |
Output is correct |
55 |
Incorrect |
99 ms |
52780 KB |
Tree @(3, 133331) appears more than once: for edges on positions 133331 and 133332 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4532 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
47 ms |
26796 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
26 ms |
17448 KB |
Output is correct |
12 |
Correct |
10 ms |
9816 KB |
Output is correct |
13 |
Correct |
8 ms |
9176 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
49 ms |
26856 KB |
Output is correct |
17 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4532 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
47 ms |
26796 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
26 ms |
17448 KB |
Output is correct |
12 |
Correct |
10 ms |
9816 KB |
Output is correct |
13 |
Correct |
8 ms |
9176 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
49 ms |
26856 KB |
Output is correct |
17 |
Runtime error |
40 ms |
8380 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4532 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
47 ms |
26796 KB |
Output is correct |
10 |
Correct |
5 ms |
8540 KB |
Output is correct |
11 |
Correct |
26 ms |
17448 KB |
Output is correct |
12 |
Correct |
10 ms |
9816 KB |
Output is correct |
13 |
Correct |
8 ms |
9176 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
49 ms |
26856 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
8640 KB |
Output is correct |
23 |
Correct |
101 ms |
53144 KB |
Output is correct |
24 |
Correct |
1 ms |
10584 KB |
Output is correct |
25 |
Correct |
2 ms |
10952 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
1 ms |
6748 KB |
Output is correct |
28 |
Correct |
42 ms |
23780 KB |
Output is correct |
29 |
Correct |
58 ms |
35624 KB |
Output is correct |
30 |
Correct |
79 ms |
45364 KB |
Output is correct |
31 |
Correct |
98 ms |
52924 KB |
Output is correct |
32 |
Correct |
1 ms |
4448 KB |
Output is correct |
33 |
Correct |
1 ms |
4576 KB |
Output is correct |
34 |
Correct |
1 ms |
4444 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
1 ms |
4444 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
39 |
Correct |
1 ms |
4444 KB |
Output is correct |
40 |
Correct |
1 ms |
4440 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |
42 |
Correct |
1 ms |
8540 KB |
Output is correct |
43 |
Correct |
1 ms |
4700 KB |
Output is correct |
44 |
Correct |
2 ms |
6600 KB |
Output is correct |
45 |
Correct |
51 ms |
30652 KB |
Output is correct |
46 |
Correct |
72 ms |
38220 KB |
Output is correct |
47 |
Correct |
70 ms |
38092 KB |
Output is correct |
48 |
Correct |
1 ms |
8536 KB |
Output is correct |
49 |
Correct |
1 ms |
8540 KB |
Output is correct |
50 |
Correct |
1 ms |
10688 KB |
Output is correct |
51 |
Correct |
2 ms |
10588 KB |
Output is correct |
52 |
Correct |
2 ms |
10588 KB |
Output is correct |
53 |
Correct |
1 ms |
10588 KB |
Output is correct |
54 |
Correct |
1 ms |
10588 KB |
Output is correct |
55 |
Incorrect |
99 ms |
52780 KB |
Tree @(3, 133331) appears more than once: for edges on positions 133331 and 133332 |
56 |
Halted |
0 ms |
0 KB |
- |