Skip to content

Commit 025ba3a

Browse files
authored
Merge pull request #1604 from AlgorithmWithGod/ksinji
[20251207] BOJ / G5 / 컨베이어 벨트 위의 로봇 / 강신지
2 parents a0bb8e5 + 5b6595a commit 025ba3a

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws Exception {
7+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
10+
int n = Integer.parseInt(st.nextToken());
11+
int k = Integer.parseInt(st.nextToken());
12+
13+
int[] belt = new int[2 * n];
14+
st = new StringTokenizer(br.readLine());
15+
for (int i = 0; i < 2 * n; i++) {
16+
belt[i] = Integer.parseInt(st.nextToken());
17+
}
18+
19+
boolean[] robot = new boolean[n];
20+
int step = 0;
21+
22+
while (true) {
23+
step++;
24+
25+
// 컨베이어 벨트 회전
26+
int last = belt[2 * n - 1];
27+
for (int i = 2 * n - 1; i >= 1; i--) {
28+
belt[i] = belt[i - 1];
29+
}
30+
belt[0] = last;
31+
32+
for (int i = n - 1; i >= 1; i--) {
33+
robot[i] = robot[i - 1];
34+
}
35+
robot[0] = false;
36+
robot[n - 1] = false;
37+
38+
// 로봇 회전
39+
for (int i = n - 1; i >= 1; i--) {
40+
if (robot[i - 1] && !robot[i] && belt[i] > 0) {
41+
robot[i] = true;
42+
robot[i - 1] = false;
43+
belt[i]--;
44+
}
45+
}
46+
robot[n - 1] = false;
47+
48+
// 0번 칸에 로봇 올리기
49+
if (!robot[0] && belt[0] > 0) {
50+
robot[0] = true;
51+
belt[0]--;
52+
}
53+
54+
// 내구도가 0인 칸의 개수가 k개 이상이라면 과정을 종료
55+
int zeroCnt = 0;
56+
for (int i = 0; i < 2 * n; i++) {
57+
if (belt[i] == 0) zeroCnt++;
58+
}
59+
if (zeroCnt >= k) {
60+
System.out.println(step);
61+
break;
62+
}
63+
}
64+
}
65+
}
66+
67+
```

0 commit comments

Comments
 (0)