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
'🟢 알고리즘 문제 풀이 > Baekjoon' 카테고리의 다른 글
| [파이썬] 백준 2595 부등호 (0) | 2023.04.13 |
|---|---|
| [파이썬] 백준 4811 알약 (0) | 2023.04.11 |
| [파이썬] 백준 12904 A와 B (0) | 2023.04.09 |
| [파이썬] 백준 5582 공통 부분 문자열 (0) | 2023.04.09 |
| [파이썬] 백준 15486 퇴사 2 (1) | 2023.04.09 |