ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

๋ฌธ์ œ ํ’€์ด

 ๋นŒ๋”ฉ์˜ ๋†’๋‚ฎ์ด๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ, ํ•˜๋‚˜์˜ ๋นŒ๋”ฉ์„ ๊ธฐ์ค€์œผ๋กœ ์ขŒ์ธก์œผ๋กœ 2์นธ, ์šฐ์ธก์œผ๋กœ 2์นธ์˜ ๋นŒ๋”ฉ ์ค‘ ๋‚ฎ์€ ๋นŒ๋”ฉ์ด ์žˆ๋Š” ๊ฒฝ์šฐ๋ฅผ ์ฐพ๋Š” ๋ฌธ์ œ์ด๋‹ค. ์ด๋•Œ ๋นŒ๋”ฉ์˜ ๋†’์ด๊ฐ€ ์ขŒ์šฐ์ธก์˜ ๋นŒ๋”ฉ ์ค‘ ๊ฐ€์žฅ ๋†’์€ ๋นŒ๋”ฉ๋ณด๋‹ค ๋†’์€ ์ธต์€ ์ „๋ง๊ถŒ์ด ํ™•๋ณด๋œ ์„ธ๋Œ€์ˆ˜์ด๋‹ค. ์ฃผ์–ด์ง„ ์ž…๋ ฅ๊ฐ’์—์„œ ์ „๋ง๊ถŒ์ด ํ™•๋ณด๋œ ์„ธ๋Œ€์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ๋œ๋‹ค.

 

์ฝ”๋“œ

for test_case in range(1, 11):
    length = int(input())
    buildings = list(map(int, input().split()))
    answer = 0

    for idx in range(2, length - 2):
        cur_height = buildings[idx]
        left = max(buildings[idx - 2:idx])
        right = max(buildings[idx + 1: idx + 3])

        if left > cur_height or right > cur_height:
            continue

        answer += cur_height - max(left, right)

    print('#' + str(test_case), answer)

 ์ขŒ์šฐ์ธก์œผ๋กœ ๋นˆ์นธ์ธ 0์ด ์ฃผ์–ด์ง€๋ฏ€๋กœ, `(2, length - 2)`์˜ ์ธ๋ฑ์Šค๋ฅผ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค.

 

728x90
๋ฐ˜์‘ํ˜•

'๐Ÿ‘จโ€๐Ÿ’ป ์ฝ”๋”ฉํ…Œ์ŠคํŠธ > SWEA' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

SWEA: 1221 GNS  (0) 2020.10.07
SWEA: 1220 Magnetic  (0) 2020.10.07
SWEA: 1215 ํšŒ๋ฌธ1  (0) 2020.10.07
SWEA: 1209 Sum  (0) 2020.10.07
SWEA: 1208 Flatten  (0) 2020.10.07
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€