백준 20055 컨베이어 벨트 위의 로봇

wook2·2021년 8월 8일
0

알고리즘

목록 보기
49/117

https://www.acmicpc.net/problem/20055

처음에 로봇이 n+1~2n까지 이동이 가능한줄 알고 문제 이해에 애를 먹었다.
로봇은 1~n 까지만 이동이 가능하며 내린 이후에는 컨베이어만 돌아가는 방식이다.

from collections import deque
n,k = list(map(int,input().split()))
a = deque(list(map(int,input().split())))
robot = deque([0] * n)
result = 0

while True:
    a.rotate(1)
    robot.rotate(1)
    robot[-1] = 0
    if sum(robot):
        for i in range(n-2,-1,-1):
            if robot[i] == 1 and robot[i+1] == 0 and a[i+1] >= 1:
                robot[i+1] = 1
                robot[i] = 0
                a[i+1] -= 1
            robot[-1] = 0
    if robot[0] == 0 and a[0] >= 1:
        robot[0] = 1
        a[0] -= 1
    result += 1
    if a.count(0) >= k:
        break

print(result)
profile
꾸준히 공부하자

0개의 댓글