Skip to content

Commit a570f44

Browse files
authored
[20250808] BOJ / G4 / 가장 큰 정사각형 / 이종환
1 parent cbcdaaf commit a570f44

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
```java
2+
import java.awt.*;
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.*;
7+
8+
public class Main {
9+
static int height, width;
10+
static int[][] arr;
11+
static int[][] dp;
12+
13+
public static void main(String[] args) throws IOException {
14+
init();
15+
int result = process();
16+
System.out.println(result * result);
17+
}
18+
19+
private static void init() throws IOException {
20+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
21+
StringTokenizer st = new StringTokenizer(br.readLine());
22+
height = Integer.parseInt(st.nextToken());
23+
width = Integer.parseInt(st.nextToken());
24+
25+
arr = new int[height][width];
26+
dp = new int[height][width];
27+
28+
for (int i = 0; i < height; i++) {
29+
String[] input = br.readLine().split("");
30+
for (int j = 0; j < width; j++) {
31+
arr[i][j] = Integer.parseInt(input[j]);
32+
}
33+
}
34+
}
35+
36+
private static int process() {
37+
int maxSize = 0;
38+
39+
// DP 초기화 및 계산
40+
for (int i = 0; i < height; i++) {
41+
for (int j = 0; j < width; j++) {
42+
if (arr[i][j] == 1) {
43+
if (i == 0 || j == 0) {
44+
dp[i][j] = 1;
45+
} else {
46+
// 왼쪽, 위쪽, 대각선 위쪽의 최솟값 + 1
47+
dp[i][j] = Math.min(dp[i-1][j],
48+
Math.min(dp[i][j-1], dp[i-1][j-1])) + 1;
49+
}
50+
maxSize = Math.max(maxSize, dp[i][j]);
51+
} else {
52+
dp[i][j] = 0;
53+
}
54+
}
55+
}
56+
57+
return maxSize;
58+
}
59+
}
60+
```

0 commit comments

Comments
 (0)