Skip to content

Commit

Permalink
feat : 빗물 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeminimini committed Nov 11, 2023
1 parent e3b5e51 commit 29950d4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/kotlin/jimin/49week/빗물.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'''
빗물을 밑에서 부터 살펴본다.
막힌 부분의 최소 최대를 구하고, 그 사이에 비어있는 곳에 빗물이 고인다.
'''

import sys
h, w = map(int, sys.stdin.readline().split())
blocks = list(map(int, sys.stdin.readline().split()))
blocks_info = [[0 for _ in range(w)] for _ in range(h)]
result = 0

for idx, val in enumerate(blocks):
for i in range(val):
blocks_info[i][idx] = 1

for i in range(h):
mini = w
maxi = 0
for j in range(w):
if blocks_info[i][j] == 1:
mini = min(mini, j)
maxi = max(maxi, j)

for j in range(mini + 1, maxi):
if blocks_info[i][j] == 0:
result += 1

print(result)




0 comments on commit 29950d4

Please sign in to comment.