728x90
📑문제링크
https://www.acmicpc.net/problem/21922
💻코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int[][] map = new int[N][M];
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < M; j++) {
map[i][j] = Integer.parseInt(st.nextToken());
}
}
int[][] dp = new int[N + 1][M + 1];
int answer = 0;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
if (map[i - 1][j - 1] != 0) {
dp[i][j] = 0;
} else {
dp[i][j] = Math.min(dp[i - 1][j - 1], Math.min(dp[i - 1][j], dp[i][j - 1])) + 1;
}
answer = Math.max(answer, dp[i][j]);
}
}
System.out.println(answer);
}
}
728x90
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm/Baekjoon] 1, 2, 3 더하기 7 - 15992 (S1/JAVA) (0) | 2025.05.12 |
---|---|
[Algorithm/Baekjoon] 카우버거 알바생 - 17208 (G4/JAVA) (0) | 2025.03.10 |
[Algorithm/Baekjoon] 퇴사 - 14501 (S3/JAVA) (0) | 2025.02.12 |
[Algorithm/Baekjoon] 학부 연구생 민상 - 21922 (G5/JAVA) (2) | 2025.01.20 |
[Algorithm/Baekjoon] 여러분의 다리가 되어 드리겠습니다! - 17352 (G5/JAVA) (0) | 2025.01.06 |