Skip to content

Commit 176cc98

Browse files
authored
[20251209] BOJ / G5 / 김밥천국의 계단 / 이강현
1 parent e989f16 commit 176cc98

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 minMoves = bfs(n);
14+
15+
if (minMoves <= k) {
16+
System.out.println("minigimbob");
17+
} else {
18+
System.out.println("water");
19+
}
20+
}
21+
22+
static int bfs(int n) {
23+
if (n == 0) return 0;
24+
25+
Queue<int[]> queue = new LinkedList<>();
26+
boolean[] visited = new boolean[n + 1];
27+
28+
queue.offer(new int[]{0, 0});
29+
visited[0] = true;
30+
31+
while (!queue.isEmpty()) {
32+
int[] cur = queue.poll();
33+
int pos = cur[0];
34+
int moves = cur[1];
35+
36+
int next1 = pos + 1;
37+
if (next1 == n) return moves + 1;
38+
if (next1 < n && !visited[next1]) {
39+
visited[next1] = true;
40+
queue.offer(new int[]{next1, moves + 1});
41+
}
42+
43+
int next2 = pos + pos / 2;
44+
if (next2 == n) return moves + 1;
45+
if (next2 < n && !visited[next2]) {
46+
visited[next2] = true;
47+
queue.offer(new int[]{next2, moves + 1});
48+
}
49+
}
50+
51+
return Integer.MAX_VALUE;
52+
}
53+
}
54+
```

0 commit comments

Comments
 (0)