728x90
😉 아이디어
1. _!skill!_적용 값을 일괄처리 후 _!board!_적용 👉 누적합 개념 사용 (카카오 가이드 참고)
😉 코드
def solution(board, skill):
answer = 0
tmp = [[0 for __ in range(len(board[0]) + 1)]for _ in range(len(board) + 1)]
for s in skill:
# 1: 공격, 2: 회복
typ, s_y, s_x, e_y, e_x, deg = s
if typ == 1:
tmp[s_y][s_x] += deg
tmp[s_y][e_x + 1] -= deg
tmp[e_y + 1][s_x] -= deg
tmp[e_y + 1][e_x + 1] += deg
else:
tmp[s_y][s_x] -= deg
tmp[s_y][e_x + 1] += deg
tmp[e_y + 1][s_x] += deg
tmp[e_y + 1][e_x + 1] -= deg
# 가로 누적합
for row in tmp:
for i in range(1, len(row)):
row[i] = row[i - 1] + row[i]
# 세로 누적합
for i in range(len(tmp[0])):
for j in range(1, len(tmp)):
tmp[j][i] = tmp[j - 1][i] + tmp[j][i]
for i in range(len(board)):
for j in range(len(board[0])):
board[i][j] -= tmp[i][j]
if board[i][j] > 0:
answer += 1
return answer
✔ 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/92344