BOJ - 1915 - 가장 큰 정사각형

Updated:

import sys

def solution():
    N, M = map(int, sys.stdin.readline().split())
    square = []

    for _ in range(N):
        square.append(list(map(int, list(sys.stdin.readline().strip()))))

    dp = [[0 for _ in range(M + 1)] for _ in range(N + 1)]

    ret = 0
    for i in range(1, N + 1):
        for j in range(1, M + 1):
            if square[i - 1][j - 1] == 1:
                dp[i][j] = min(
                    dp[i][j-1],
                    dp[i-1][j],
                    dp[i-1][j-1]
                ) + 1

                if dp[i][j] > ret:
                    ret = dp[i][j]
    print(ret**2)

solution()

https://www.acmicpc.net/problem/1915

Categories:

Updated:

Leave a comment