빌딩을 가로로 눕혔다고 생각한다.
즉, n개의 빌딩 수를 행의 개수로 생각하고 길이만큼 1을 채운다.
빌딩의 최대 길이는 255이므로 배열의 길이를 255까지 지정해준다.
arr[i][j] == 1
이고, 배열의 양옆인 i-2, i-1, i+1, i+2
를 비교해 모두 0이면 횟수 cnt
에 더해준다.
import sys
sys.stdin = open("input.txt", "r")
for _ in range(1, 11):
n = int(input())
buildings = list(map(int, input().split()))
arr = [[0] * (255) for _ in range(n)]
for i in range(n):
h = buildings[i]
for j in range(h): # 건물 높이만큼 1을 채운다
arr[i][j] = 1
cnt = 0
for i in range(n):
for j in range(255):
if arr[i][j] == 1: # 만약 1이라면, 양옆의 2칸이 비었는 지 확인
if arr[i+1][j] == 0 and arr[i+2][j] == 0 and arr[i-1][j] == 0 and arr[i-2][j] == 0:
cnt += 1
print(cnt)