아이디어
풀이
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