1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
#include <iostream>
#include <vector>
using namespace std;
int n, m;
int map[51][51][4];
int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};
bool visited[51][51];
int room[102], roomNum[51][51];
void dfs(int x, int y, int label)
{
if (visited[x][y])
return;
visited[x][y] = true;
for (int i = 0; i < 4; i++)
{
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= m || ny < 0 || ny >= n || visited[nx][ny])
continue;
if (!map[x][y][i])
{
roomNum[nx][ny] = label;
room[label]++;
dfs(nx, ny, label);
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
int tmp;
cin >> tmp;
for (int k = 0; k < 4; k++)
{
if (tmp & (1 << k))
map[i][j][k] = 1;
}
}
}
int label = 0;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < 4; k++)
{
if (!visited[i][j] && !map[i][j][k])
{
roomNum[i][j] = ++label;
room[label]++;
dfs(i, j, label);
}
}
}
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (roomNum[i][j] == 0)
{
roomNum[i][j] = ++label;
room[label]++;
}
}
}
cout << label << '\n';
int maxWidth = 0;
for (int i = 1; i <= label; i++) {
maxWidth = maxWidth < room[i] ? room[i] : maxWidth;
}
cout << maxWidth << '\n';
int max = 0;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < 4; k++)
{
int nx = i + dx[k];
int ny = j + dy[k];
if (nx < 0 || nx >= m || ny < 0 || ny >= n) continue;
if (roomNum[i][j] != roomNum[nx][ny])
{
max = max < room[roomNum[i][j]] + room[roomNum[nx][ny]] ? room[roomNum[i][j]] + room[roomNum[nx][ny]]: max ;
}
}
}
}
cout << max << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
BOJ/C++