Notice
Recent Posts
Recent Comments
Link
«   2024/04   »
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
Archives
Today
Total
관리 메뉴

0과 1 사이

[파이썬(python)] 프로그래머스 데브 매칭 행렬 테두리 회전하기 본문

코딩테스트

[파이썬(python)] 프로그래머스 데브 매칭 행렬 테두리 회전하기

고후 2022. 4. 1. 14:41

https://programmers.co.kr/learn/courses/30/lessons/77485

 

코딩테스트 연습 - 행렬 테두리 회전하기

6 6 [[2,2,5,4],[3,3,6,6],[5,1,6,3]] [8, 10, 25] 3 3 [[1,1,2,2],[1,2,2,3],[2,1,3,2],[2,2,3,3]] [1, 1, 5, 3]

programmers.co.kr

 

def solution(rows, columns, queries):
    answer = []
    matrix = [[i+m*columns for i in range(1, columns+1)] for m in range(rows)]
    
    for q in queries:
        x1, y1, x2, y2 = q[0]-1, q[1]-1, q[2]-1, q[3]-1
        
        tmp = matrix[x1][y1]
        min_tmp = tmp
        
        x, y = x1, y1
        
        while x < x2:
            matrix[x][y] = matrix[x+1][y]
            min_tmp = min(min_tmp, matrix[x][y])
            x += 1
        
        while y < y2:
            matrix[x][y] = matrix[x][y+1]
            min_tmp = min(min_tmp, matrix[x][y])
            y += 1
        
        while x1 < x:
            matrix[x][y] = matrix[x-1][y]
            min_tmp = min(min_tmp, matrix[x][y])
            x -= 1
        
            
        while y1 < y:
            if y == y1+1:
                matrix[x][y] = tmp
            else:
                matrix[x][y] = matrix[x][y-1]
            min_tmp = min(min_tmp, matrix[x][y])
            y -= 1
            
        answer.append(min_tmp)
            
    
    return answer
Comments