-
Notifications
You must be signed in to change notification settings - Fork 0
/
220520_파괴되지않은건물_L3.py
36 lines (30 loc) · 1013 Bytes
/
220520_파괴되지않은건물_L3.py
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
# 누적 합
def solution(board, skill):
answer = 0
sum_d = [[0 for i in range(len(board[0])+1)] for j in range(len(board)+1)]
for t, r1, c1, r2, c2, degree in skill:
if t == 1:
sum_d[r1][c1] -= degree
sum_d[r1][c2 + 1] += degree
sum_d[r2 + 1][c1] += degree
sum_d[r2 + 1][c2 + 1] -= degree
else:
sum_d[r1][c1] += degree
sum_d[r1][c2 + 1] -= degree
sum_d[r2 + 1][c1] -= degree
sum_d[r2 + 1][c2 + 1] += degree
# 행 방향
for i in range(len(board)):
for j in range(len(board[0])):
sum_d[i][j+1] += sum_d[i][j]
# 열 방향
for i in range(len(board)):
for j in range(len(board[0])):
sum_d[i+1][j] += sum_d[i][j]
# 기존 배열에 더함
for i in range(len(board)):
for j in range(len(board[0])):
board[i][j] += sum_d[i][j]
if board[i][j] > 0:
answer += 1
return answer