|
| 1 | +```java |
| 2 | +import java.io.*; |
| 3 | +import java.util.StringTokenizer; |
| 4 | + |
| 5 | +public class BJ_1915_가장_큰_정사각형 { |
| 6 | + |
| 7 | + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 8 | + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 9 | + private static StringTokenizer st; |
| 10 | + |
| 11 | + private static int N, M; |
| 12 | + private static int[][] map; |
| 13 | + private static int[][] dp; |
| 14 | + private static int maxVal; |
| 15 | + |
| 16 | + public static void main(String[] args) throws IOException { |
| 17 | + init(); |
| 18 | + sol(); |
| 19 | + } |
| 20 | + |
| 21 | + private static void init() throws IOException { |
| 22 | + st = new StringTokenizer(br.readLine()); |
| 23 | + N = Integer.parseInt(st.nextToken()); |
| 24 | + M = Integer.parseInt(st.nextToken()); |
| 25 | + |
| 26 | + map = new int[N + 1][M + 1]; |
| 27 | + dp = new int[N + 1][M + 1]; |
| 28 | + for (int i = 1; i <= N; i++) { |
| 29 | + String s = br.readLine(); |
| 30 | + for (int j = 1; j <= M; j++) { |
| 31 | + map[i][j] = s.charAt(j - 1) - '0'; |
| 32 | + } |
| 33 | + } |
| 34 | + maxVal = 0; |
| 35 | + } |
| 36 | + |
| 37 | + private static void sol() throws IOException { |
| 38 | + for (int i = 1; i <= N; i++) { |
| 39 | + for (int j = 1; j <= M; j++) { |
| 40 | + if (map[i][j] == 0) { |
| 41 | + dp[i][j] = 0; |
| 42 | + continue; |
| 43 | + } |
| 44 | + dp[i][j] = Math.min(dp[i - 1][j - 1], Math.min(dp[i - 1][j], dp[i][j - 1])) + 1; |
| 45 | + maxVal = Math.max(maxVal, dp[i][j]); |
| 46 | + } |
| 47 | + } |
| 48 | + bw.write((maxVal * maxVal) + "\n"); |
| 49 | + bw.flush(); |
| 50 | + bw.close(); |
| 51 | + br.close(); |
| 52 | + } |
| 53 | + |
| 54 | +} |
| 55 | +``` |
0 commit comments