백준 - 1051번 숫자 정사각형
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
square = []
for _ in range(N):
square.append(list(map(int, list(input().rstrip()))))
max_s = 1 # 가장 큰 정사각형
for i in range(N-1):
for j in range(M-1):
L = min(N-i, M-j)
for k in range(1, L):
a = square[i][j]
b = square[i][j+k]
c = square[i+k][j]
d = square[i+k][j+k]
if a == b == c == d:
if max_s < (k+1) * (k+1):
max_s = (k+1) * (k+1)
print(max_s)
백준 - 1783번 병든 나이트
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
if N == 1:
print(1)
elif N == 2:
if M == 1 or M == 2: print(1)
elif M == 3 or M == 4: print(2)
elif M == 5 or M == 6: print(3)
else: print(4)
elif N >= 3:
if M <= 4: print(M)
elif M == 5 or M ==6: print(4)
else: print(M-2)