[백준] 20055 컨베이어 벨트 위의 로봇 (Python 파이썬)

dh·2022년 10월 20일
0
post-thumbnail

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

문제접근

문제의 조건대로 진행하면 되는데 조건도 많고 복잡해서 문제 이해하는데 시간이 오래걸렸고 푸는데도 오래 걸렸던것 같다.

코드

from collections import deque

N, K = map(int,input().split())
arr = list(map(int,input().split()))
belt = deque(arr)
r= [0]*N
robot = deque(r)

cnt = 0
stage = 1


while True:
    # 1. 벨트가 로봇과 함꼐 한 칸 회전
    belt.rotate(1)
    robot.rotate(1)
    robot[N-1] = 0

    for i in range(N-2,-1,-1):
        # 2. 가장 먼저 벨트에 올라간 로봇부터 이동
        if robot[i]==1:
            if i == N - 1:
                robot[i] = 0
                continue
            if belt[i+1] > 0 and robot[i+1]==0:
                belt[i+1] -= 1
                robot[i+1], robot[i] = 1,0
                if i+1==N-1:
                    robot[i+1]=0

    # 3. 올리는 위치에 내구도 0이 아니면 로봇 올리기
    if robot[0]==0 and belt[0] > 0:
        belt[0] -= 1
        robot[0] = 1


    if list(belt).count(0)>=K:
        break
    stage+=1

print(stage)

0개의 댓글