[프로그래머스] 파괴되지 않은 건물

이강혁·4일 전
0

프로그래머스

목록 보기
91/92

https://school.programmers.co.kr/learn/courses/30/lessons/92344

from collections import defaultdict

def solution(board, skill):
    answer = 0
    
    space = defaultdict(int)
    
    total = [[0] * (len(board[0]) + 1) for _ in range(len(board) + 1)]
    
    for t, r1, c1, r2, c2, degree in skill:
        degree = -degree if t == 1 else degree
        total[r1][c1] += degree
        total[r1][c2 + 1] += -degree
        total[r2 + 1][c1] += -degree
        total[r2 + 1][c2 + 1] += degree
    
    for i in range(len(board)):
        for j in range(1, len(board[0])):
            total[i][j] += total[i][j - 1]

    for j in range(len(board)):
        for i in range(1, len(board)):
            total[i][j] += total[i - 1][j]
    
    for i in range(len(board)):
        for j in range(len(board[0])):
            if board[i][j] + total[i][j] > 0:
                answer += 1
    return answer
profile
사용자불량

0개의 댓글

관련 채용 정보