File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments