20055번: 컨베이어 벨트 위의 로봇 (acmicpc.net)
20055번: 컨베이어 벨트 위의 로봇
길이가 N인 컨베이어 벨트가 있고, 길이가 2N인 벨트가 이 컨베이어 벨트를 위아래로 감싸며 돌고 있다. 벨트는 길이 1 간격으로 2N개의 칸으로 나뉘어져 있으며, 각 칸에는 아래 그림과 같이 1부
www.acmicpc.net
from collections import deque
N, K = map(int,input().split())
A = list(map(int,input().split()))
robot = deque() #로봇이 있는 위치
in_robot = [0]*(2*N)
queue = deque()
for i in range(2*N-1,-1,-1):
queue.append(i)
result = 0
count = 0
while True:
result+=1 #회전하기
put = queue.popleft()
queue.append(put)
left = (put+N-1)%(N*2)
for _ in range(len(robot)):
i = robot.popleft()
if(i==left):
in_robot[i]=0
else:
robot.append(i)
for _ in range(len(robot)): #로봇 옮기기
i = robot.popleft()
next=i+1
if(next==2*N): next=0 #이동할 다음 칸
if(A[next]>0): #다음 칸의 내구도가 0이 아니면
if(next==left):
in_robot[i]=0
A[next]-=1
if(A[next]==0):
count+=1
continue
if(in_robot[next]==0): #다음 칸에 로봇이 없으면
if(next!=left): #만약 다음칸이 내리는 위치가 아니면
robot.append(next) #로봇 옮기기
in_robot[next]=1
in_robot[i]=0
A[next]-=1
if(A[next]==0):
count+=1
else:
robot.append(i)
else:
robot.append(i)
if(A[put]>0): #로봇 올리기
A[put]-=1
robot.append(put)
in_robot[put]=1
if(A[put]==0):
count+=1
if(count>=K):
print(result)
break
'코딩 > 백준' 카테고리의 다른 글
[python] 백준 17281 야구 (0) | 2023.03.09 |
---|---|
[python] 백준 17471 게리맨더링 (0) | 2023.03.02 |
[python] 백준 10026 적록 색약 DFS (1) | 2023.02.25 |
[python] 백준 1667 단지번호붙이기 (0) | 2023.02.25 |
[pytho] 백준 5014 스타트링크 (0) | 2023.02.25 |