-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomePartyx2.java
More file actions
48 lines (40 loc) · 1.54 KB
/
HomePartyx2.java
File metadata and controls
48 lines (40 loc) · 1.54 KB
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
package Notes;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class HomePartyx2 {
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] dimensions = bf.readLine().split(" ");
int R = Integer.parseInt(dimensions[0]);
int C = Integer.parseInt(dimensions[1]);
char[][] apartment = new char[R][C];
for (int i = 0; i < R; i++) {
String line = bf.readLine();
for (int j = 0; j < C; j++) {
apartment[i][j] = line.charAt(j);
}
}
int maxPeople = 0;
int[] dx = {-1, 0, 1, 0};
int[] dy = {0, 1, 0, -1};
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (apartment[i][j] == '.') {
int perimeter = 0;
for (int k = 0; k < 4; k++) {
int ni = i + dx[k];
int nj = j + dy[k];
if (ni >= 0 && ni < R && nj >= 0 && nj < C && apartment[ni][nj] == '.') {
perimeter++;
}
}
maxPeople = Math.max(maxPeople, perimeter);
}
}
}
System.out.println(maxPeople-1);
}
}
}