practivceAlgorithm/백준

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

findTheValue 2021. 8. 5. 09:19

절차대로 구현하는 구현문제이다. 이런게 난이도 책정은 낮게되어이쓴데 실제로 좀 그림그리는게 필요해서 체감상 어려웠다 앞으로 구현문제 많이 풀어봐야겟다는 생각을 했다

import sys 
input = sys.stdin.readline 
from collections import deque 

N, K = map(int, input().split()) 
conveier = deque()
conveier.extend(list(map(int, input().split())))
robot = deque()
robot.extend([0]*N)
K_cnt = conveier.count(0)
ans=0
while K_cnt <K:
    # conveier,robot한칸씩 회전
    conveier.rotate(1)
    robot.rotate(1)
    robot[-1]=0
    # 로봇이 한칸 이동할 수 있으면 이동한다.
    for i in range(N-2,-1,-1):
        if robot[i] and not robot[i+1] and conveier[i+1]:
            robot[i+1] = 1
            robot[i] = 0
            conveier[i+1] -= 1
            if not conveier[i+1]:
                K_cnt+=1
    # 내리는위치 로봇은 내린다.
    robot[-1] = 0
    # 올리는 위치에 있는 칸이 내구도가 0이 아니면 로봇 올린다.
    if conveier[0]:
        robot[0]=1
        conveier[0]-=1
        if not conveier[0]:
            K_cnt+=1
    ans+=1
print(ans)

'practivceAlgorithm > 백준' 카테고리의 다른 글

[백준][Python] 3190 뱀  (0) 2021.08.06
[백준][Python] 14503 로봇청소기  (0) 2021.08.05
[백준][Python] 7511 소셜네트워킹  (0) 2021.08.05
[백준][Python] 14501 퇴사  (0) 2021.08.03
[백준][Python] 5972 택배배송  (0) 2021.08.03