234. 컨베이어 벨트 위의 로봇

아현·2021년 8월 5일
0

Algorithm

목록 보기
244/400
post-thumbnail

백준





1. Python


rotate 라이브러리


from collections import deque

n, k = map(int,input().split())
durability = deque(list(map(int, input().split())))
belt = deque([0] * n)
count = 0

while durability.count(0) < k:
    count += 1
    '''
    d = durability.pop()
    durability.insert(0, d)
    
    belt.pop()
    belt.insert(0,0)
    '''
    durability.rotate(1)
    belt.rotate(1)

    belt[-1] = 0

    for i in range(n - 2, 0, -1):
        if belt[i] and durability[i + 1] and (not belt[i + 1]):
            belt[i] = 0
            belt[i + 1] = 1
            durability[i + 1] -= 1

    belt[-1] = 0

    if durability[0] and not belt[0]:
        belt[0] = 1
        durability[0] -= 1
    
print(count)




rotate 라이브러리 미사용



n, k = map(int,input().split())
durability = list(map(int, input().split()))
belt = [0] * n
count = 0

while durability.count(0) < k:
    count += 1
    d = durability.pop()
    durability.insert(0, d)
    
    belt.pop()
    belt.insert(0,0)

    belt[n - 1] = 0

    for i in range(n - 2, 0, -1):
        if belt[i] and durability[i + 1] and (not belt[i + 1]):
            belt[i] = 0
            belt[i + 1] = 1
            durability[i + 1] -= 1

    belt[n - 1] = 0

    if durability[0] and not belt[0]:
        belt[0] = 1
        durability[0] -= 1
    
print(count)






profile
For the sake of someone who studies computer science

0개의 댓글