π 1915 λ¬Έμ
n×mμ 0, 1λ‘ λ λ°°μ΄μ΄ μλ€. μ΄ λ°°μ΄μμ 1λ‘ λ κ°μ₯ ν° μ μ¬κ°νμ ν¬κΈ°λ₯Ό ꡬνλ νλ‘κ·Έλ¨μ μμ±νμμ€.
0 1 0 0 0 1 1 1 1 1 1 0 0 0 1 0 μμ κ°μ μμ μμλ κ°μ΄λ°μ 2×2 λ°°μ΄μ΄ κ°μ₯ ν° μ μ¬κ°νμ΄λ€.
μ λ ₯
첫째 μ€μ n, m(1 ≤ n, m ≤ 1,000)μ΄ μ£Όμ΄μ§λ€. λ€μ nκ°μ μ€μλ mκ°μ μ«μλ‘ λ°°μ΄μ΄ μ£Όμ΄μ§λ€.
μΆλ ₯
첫째 μ€μ κ°μ₯ ν° μ μ¬κ°νμ λμ΄λ₯Ό μΆλ ₯νλ€.
π§ νμ΄
λμ νλ‘κ·Έλλ°μ μ΄μ©νμ¬ νμλ€.
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
arr = []
dp = [[0] * m for _ in range(n)]
for _ in range(n):
arr.append(list(map(int, list(input().rstrip()))))
answer = 0
for i in range(n):
for j in range(m):
if i == 0 or j == 0:
dp[i][j] = arr[i][j]
elif arr[i][j] == 0:
dp[i][j] = 0
else:
dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
answer = max(dp[i][j], answer)
print(answer * answer)
728x90