[알고리즘/백준] 20055번 : 컨베이어 벨트 위의 로봇(python)

유현민·2022년 5월 28일
0

알고리즘

목록 보기
192/253


  1. 칸 회전(rotate사용)
    1-1. robot[-1] = 0 마지막 로봇 내리기

  2. 로봇 이동(제일 오른쪽 로복 찾아서)
    2-1. 벨트 내구도 체크
    2-2. 로봇 유,무 체크
    2-3. 마지막 로봇 내리기

  3. 첫 칸 내구도 체크

  4. 0 갯수 체크

from collections import deque


def solution():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    robot = deque([0] * N)
    belt = deque(a)

    ans = 0
    while belt.count(0) < K:
        # 한 칸 회전
        belt.rotate(1)
        robot.rotate(1)

        # 로봇 내리기
        robot[N - 1] = 0

        # 로봇 이동
        for i in range(N - 2, 0, -1):
            if robot[i] and not robot[i + 1] and belt[i + 1]:
                robot[i + 1] = 1
                robot[i] = 0
                belt[i + 1] -= 1
            robot[-1] = 0

        # 첫 칸 체크
        if belt[0]:
            robot[0] = 1
            belt[0] -= 1
        ans += 1
    print(ans)


if __name__ == "__main__":
    solution()

profile
smilegate megaport infra

0개의 댓글