728x90

오랜만에 집중해서 답까지 구했다. 노가다 식이기는 하지만 맞아서 좋다.

 

 
import sys
 
 
N, M = map(int, input().split())
 
s = list(map(int,input().split(" ")))
 
 
# 제일 위 왼쪽 부터 탐색 -> 벽이 나오면 count 증가 ( 가능하니까 )
# -> 벽이 나오면 count append, 초기화 -> 끝인데 벽이 아니면 count 초기화
# -> 새 라인 갈때 count 초기화
 
 
def check(temp):
 
    # 0이 1 사이에 끼어 있으면 answer+=1
 
    count = False
 
    answer = 0
 
    deque = [ ]
 
    # 가장 첫 1. 가장 뒤 찾고 그 사이의 0 개수 return
 
    if 1 not in temp:
        return 0
    first = temp.index(1)
    last = list(reversed(temp)).index(1)
 
    check = temp[first+1:len(temp)-last-1]
 
    if len(check)==0:
        return 0
    return check.count(0)
 
 
 
 
 
 
    return answer
 
 
 
k = [[0]*N for i in range(M)]
 
for i in range(0,len(s)):
 
    for j in range(0,s[i]):
 
        k[i][j]=1
 
index = 0
answer = 0
 
 
while True:
 
    count = 0
 
    if index == N:
        break
 
    temp = [ ]
 
    for i in range(0,M):
 
        temp.append(k[i][index])
 
    answer += check(temp)
 
 
 
    index+=1
 
print(answer)
 
728x90

+ Recent posts