File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ # https://www.acmicpc.net/problem/20055
2+ # 컨베이어 벨트 위의 로봇 , 골드5
3+
4+ import sys
5+ import copy
6+ from collections import deque , defaultdict
7+ from typing import List
8+ sys .stdin = open ('../../../input.txt' , 'r' )
9+
10+ N , K = map (int ,input ().split (" " ))
11+ belts = deque (map (int ,input ().split (" " ))) # 내구도
12+ TOTAL_LENGTH = 2 * N
13+
14+ robots = deque ([False ] * N ) # 로봇의 존재 유무
15+
16+ answer = None
17+ step = 1
18+ count_zero = 0
19+
20+ while (True ):
21+ #1. 회전 (내구도 감소X)
22+ # 벨트 회전
23+ belts .rotate (1 )
24+ robots .rotate (1 )
25+
26+ # "내리는 위치"이면 그 즉시 벨트에서 내린다.
27+ robots [N - 1 ] = False
28+
29+
30+ #2. 로봇 이동
31+ for i in range (N - 2 ,- 1 ,- 1 ):
32+ if robots [i ]:
33+ if not robots [i + 1 ] and belts [i + 1 ] >= 1 :
34+ robots [i ] = False
35+ robots [i + 1 ] = True
36+ belts [i + 1 ] -= 1
37+
38+ if belts [i + 1 ] == 0 :
39+ count_zero += 1
40+
41+ # "내리는 위치"이면 그 즉시 벨트에서 내린다.
42+ robots [N - 1 ] = False
43+
44+ #3. 새로운 로봇 투입
45+ if (belts [0 ] != 0 ):
46+ robots [0 ] = True
47+ belts [0 ] -= 1 # 투입 위치 내구도 감소
48+ if (belts [0 ] == 0 ):
49+ count_zero += 1
50+
51+ if count_zero >= K :
52+ answer = step
53+ break
54+
55+ step += 1
56+
57+ print (answer )
58+
You can’t perform that action at this time.
0 commit comments