Skip to content

Commit 7e88e16

Browse files
committed
97차 1번 문제풀이
1 parent af91a58 commit 7e88e16

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

live9/test97/문제1/백유진.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def solution(board, skill):
2+
n = len(board)
3+
m = len(board[0])
4+
5+
acc = [[0] * (m + 1) for _ in range(n + 1)]
6+
7+
# skill 명령 누적합 배열에 저장
8+
for t, r1, c1, r2, c2, degree in skill:
9+
diff = degree if t == 2 else -degree
10+
acc[r1][c1] += diff
11+
acc[r1][c2 + 1] -= diff
12+
acc[r2 + 1][c1] -= diff
13+
acc[r2 + 1][c2 + 1] += diff
14+
15+
# 가로 누적합
16+
for i in range(n):
17+
for j in range(1, m):
18+
acc[i][j] += acc[i][j - 1]
19+
20+
# 세로 누적합
21+
for j in range(m):
22+
for i in range(1, n):
23+
acc[i][j] += acc[i - 1][j]
24+
25+
answer = 0
26+
for i in range(n):
27+
for j in range(m):
28+
board[i][j] += acc[i][j]
29+
if board[i][j] > 0:
30+
answer += 1
31+
32+
return answer

0 commit comments

Comments
 (0)