[SWEA] 1206. [S/W 문제해결 기본] 1일차 - View - Python

SWEA '1206. [S/W 문제해결 기본] 1일차' 문제 풀이를 정리했습니다.

2024-09-25조회수 -
PythonAlgorithm

풀이

조망권이 확보되는 조건을 만족하면 왼쪽 2칸, 오른쪽 2칸 중 가장 높은 빌딩의 높이보다 높은 만큼 세대의 조망권이 확보된다.

코드

# 1206
# [S/W 문제해결 기본] 1일차 - View
 
for test_case in range(1,11):
    n = int(input())
    heights = list(map(int, input().split()))
    result = 0
    for i in range(2,n-2):
        conditions = [heights[i] > heights[i-2], heights[i] > heights[i-1],
                  heights[i] > heights[i+2], heights[i] > heights[i+1]]
        comp = [heights[i-2],heights[i-1],heights[i+1],heights[i+2]]
        if all(conditions):
            result += heights[i] - max(comp)
    print(f"#{test_case} {result}")

출처: SWEA https://swexpertacademy.com/main/main.do

Comments

© 2026. Kwon In. All rights reserved.