Skip to content

Commit d1e4a50

Browse files
authored
[20251122] BOJ / G5 / 김밥천국의 계단 / 설진영
1 parent 2c76b66 commit d1e4a50

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
public static void main(String[] args) throws IOException {
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[] dist = new int[N + 1];
14+
Arrays.fill(dist, -1);
15+
16+
ArrayDeque<Integer> queue = new ArrayDeque<>();
17+
queue.offer(0);
18+
dist[0] = 0;
19+
20+
while (!queue.isEmpty()) {
21+
int cur = queue.poll();
22+
23+
if (dist[cur] >= K) continue;
24+
25+
int next1 = cur + 1;
26+
if (next1 <= N && dist[next1] == -1) {
27+
dist[next1] = dist[cur] + 1;
28+
queue.offer(next1);
29+
}
30+
31+
int next2 = cur + cur / 2;
32+
if (next2 <= N && dist[next2] == -1) {
33+
dist[next2] = dist[cur] + 1;
34+
queue.offer(next2);
35+
}
36+
}
37+
38+
if (dist[N] != -1 && dist[N] <= K) {
39+
System.out.println("minigimbob");
40+
} else {
41+
System.out.println("water");
42+
}
43+
}
44+
}
45+
```

0 commit comments

Comments
 (0)