[Algorithm] 백준 14719 : 빗물

채멈·2024년 2월 5일

Algorithm

목록 보기
19/24
post-thumbnail

문제
https://www.acmicpc.net/problem/14719
풀이
https://github.com/nowChae/algorithm/blob/master/%EB%B0%B1%EC%A4%80/Gold/14719.%E2%80%85%EB%B9%97%EB%AC%BC/%EB%B9%97%EB%AC%BC.py

< 풀이 코드 >

import sys
input = sys.stdin.readline

H, W = map(int,input().split())
heights = list(map(int,input().split()))

result = 0

for i in range(H):
    counts = []
    count = 0
    is_state = False

    for j in range(W):
        if heights[j] == 0:
            if is_state:
                count += 1
        else:
            heights[j] -= 1
            if not is_state:
                is_state = True
            counts.append(count)
            count = 0

    result += sum(counts)
print(result)
profile
공부 기록 차곡차곡 ( ੭ ・ᴗ・ )੭

0개의 댓글