프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
아이디어
풀이
def solution(rows, columns, queries):
template = [[y * columns + x + 1 for x in range(columns)] for y in range(rows)]
answer = []
for query in queries:
y1, x1, y2, x2 = [i - 1 for i in query]
min_value = float('inf')
top_left = template[y1][x1]
# 좌
for y in range(y1, y2):
template[y][x1] = template[y + 1][x1]
min_value = min(min_value, template[y][x1])
# 하
for x in range(x1, x2):
template[y2][x] = template[y2][x + 1]
min_value = min(min_value, template[y2][x])
# 우
for y in range(y2, y1, -1):
template[y][x2] = template[y - 1][x2]
min_value = min(min_value, template[y][x2])
# 상
for x in range(x2, x1 + 1, -1):
template[y1][x] = template[y1][x - 1]
min_value = min(min_value, template[y1][x])
template[y1][x1 + 1] = top_left
min_value = min(min_value, top_left)
answer.append(min_value)
return answer
'학습 노트 > 알고리즘 (Python)' 카테고리의 다른 글
99클럽 - H-Index, 프로세스 (0) | 2024.04.24 |
---|---|
99클럽 - 제리와 톰1 (0) | 2024.04.22 |
99클럽 - 큰 수 만들기 (0) | 2024.04.20 |
99클럽 - 공원 산책, 예상 대진표 (0) | 2024.04.20 |
99클럽 - 전력망을 둘로 나누기 (0) | 2024.04.18 |