Skip to content

Commit 2d14b33

Browse files
committed
92차 2번 문제풀이
1 parent 5cdd489 commit 2d14b33

1 file changed

Lines changed: 29 additions & 27 deletions

File tree

live9/test92/문제2/백유진.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
def solution(board, skill):
2-
answer = len(board)*len(board[0])
2+
n = len(board)
3+
m = len(board[0])
34

4-
# broken = set()
5+
acc = [[0] * (m + 1) for _ in range(n + 1)]
56

6-
for s in skill:
7-
stype, r1, c1, r2, c2, degree = s
8-
for r in range(r1, r2+1):
9-
for c in range(c1, c2+1):
10-
check = False
11-
if stype == 1:
12-
if board[r][c] <= 0:
13-
check = True
14-
board[r][c] -= degree
15-
if board[r][c] <= 0:
16-
if not check:
17-
answer -= 1
18-
elif stype == 2:
19-
if board[r][c] <= 0:
20-
check = True
21-
board[r][c] += degree
22-
if board[r][c] > 0:
23-
if check:
24-
answer += 1
25-
# for i in range(len(board)):
26-
# for j in range(len(board[0])):
27-
# if board[i][j] > 0:
28-
# answer += 1
29-
# print(len(board)*len(board[0])-len(broken))
30-
return answer
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)