-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLv2_행렬_테두리_회전하기.py
More file actions
40 lines (32 loc) · 1.37 KB
/
Copy pathLv2_행렬_테두리_회전하기.py
File metadata and controls
40 lines (32 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def solution(rows, columns, queries):
answer = []
matrix = [ [i*columns+j+1 for j in range(columns)] for i in range(rows) ]
if len(queries) != 1:
for x1, y1, x2, y2 in queries:
x1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1
standard = matrix[x1][y1]
minimum = standard
for i in range(x1, x2):
temp = matrix[i+1][y1]
matrix[i][y1] = temp
minimum = min(minimum, temp)
for i in range(y1, y2):
temp = matrix[x2][i+1]
matrix[x2][i] = temp
minimum = min(minimum, temp)
for i in range(x2, x1, -1):
temp = matrix[i-1][y2]
matrix[i][y2] = temp
minimum = min(minimum, temp)
for i in range(y2, y1, -1):
temp = matrix[x1][i-1]
matrix[x1][i] = temp
minimum = min(minimum, temp)
matrix[x1][y1+1] = standard
answer.append(minimum)
else:
answer.append(matrix[queries[0][0]-1][queries[0][1]]-1)
return answer
print(solution(6, 6, [[2,2,5,4],[3,3,6,6],[5,1,6,3]])) # [8, 10, 25]
print(solution(3, 3, [[1,1,2,2],[1,2,2,3],[2,1,3,2],[2,2,3,3]])) # [1, 1, 5, 3]
print(solution(100, 97, [[1,1,100,97]])) # [1]