Skip to content

Commit f74af1f

Browse files
committed
[BOJ] 컨베이어 벨트 위의 로봇 / 골드5 / 45분 실패
https://www.acmicpc.net/problem/20055
1 parent 6613ac9 commit f74af1f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from collections import deque
2+
3+
n, k = map(int, input().split())
4+
a = deque(map(int, input().split())) # 내구도. A1, A2, ..., A2N
5+
robot = deque([0] * n) # 벨트위에 있는 로봇
6+
result = 0
7+
8+
while True:
9+
result += 1
10+
# 1. 벨트 회전한다.
11+
a.rotate(1)
12+
robot[-1] = 0
13+
robot.rotate(1)
14+
robot[-1] = 0 # 내리는 위치에 도달한 경우, 즉시 내림
15+
# 2. 로봇 이동하기. 이동하려는 칸에 로봇 x, 내구도 1이상 남아야함.
16+
for i in range(n - 2, -1, -1): # 먼저 올라간 로봇부터 진행
17+
if a[i + 1] >= 1 and robot[i + 1] == 0 and robot[i] == 1:
18+
robot[i + 1] = 1
19+
robot[i] = 0
20+
a[i + 1] -= 1
21+
robot[-1] = 0 # 내리는 위치에 도달한 경우, 즉시 내림
22+
# 3. 올리는 위치에 내구도 0 아니면 로봇 올리기 & 내구도 감소
23+
if a[0] != 0 and robot[0] != 1:
24+
robot[0] = 1
25+
a[0] -= 1
26+
# 4. 내구도 0인 칸 수가 k이상이면 종료
27+
if a.count(0) >= k:
28+
break
29+
print(result)

0 commit comments

Comments
 (0)