갈색, 노란색 격자 개수 주어짐.
가로가 세로보다 상항 같거나 큼.
갈색이 노란색을 덮어쓴다.
def solution(brown, yellow):
total = brown + yellow
# 가능한 가로, 세로 조합 찾기
for width in range(3, total + 1): # 변경된 부분
if total % width == 0:
height = total // width
# 조건 확인
if width >= height and (width-2) * (height-2) == yellow:
return [width, height]
# 없는 경우 (이 경우는 문제 조건상 발생하지 않습니다)
return None
# 테스트
print(solution(10, 2)) # [4, 3]
print(solution(8, 1)) # [3, 3]
print(solution(24, 24)) # [8, 6]
print(solution(12, 1)) # [6, 2]
가로 길이는 3이상, xy = a + b, y = (x-2) (y-2) 인 것을 활용해서 문제를 해결하면 된다.