Skip to content

Commit 8968a99

Browse files
committed
[20251104] BOJ / G5 / 김밥천국의 계단 / 김민진
1 parent d24e320 commit 8968a99

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
```java
2+
import java.io.*;
3+
import java.util.ArrayDeque;
4+
import java.util.Arrays;
5+
import java.util.Queue;
6+
import java.util.StringTokenizer;
7+
8+
public class BJ_28069_김밥천국의_계단 {
9+
10+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
12+
private static StringTokenizer st;
13+
14+
private static int N, K, nxt;
15+
private static int[] minCnt;
16+
private static Queue<Node> q;
17+
18+
private static class Node {
19+
int step;
20+
int cnt;
21+
22+
Node(int step, int cnt) {
23+
this.step = step;
24+
this.cnt = cnt;
25+
}
26+
}
27+
28+
public static void main(String[] args) throws IOException {
29+
init();
30+
sol();
31+
32+
bw.flush();
33+
bw.close();
34+
br.close();
35+
}
36+
37+
private static void init() throws IOException {
38+
st = new StringTokenizer(br.readLine());
39+
N = Integer.parseInt(st.nextToken());
40+
K = Integer.parseInt(st.nextToken());
41+
42+
minCnt = new int[N + 1];
43+
Arrays.fill(minCnt, Integer.MAX_VALUE);
44+
45+
q = new ArrayDeque<>();
46+
q.offer(new Node(0, 0));
47+
minCnt[0] = 0;
48+
}
49+
50+
private static void sol() throws IOException {
51+
while (!q.isEmpty()) {
52+
Node cur = q.poll();
53+
54+
if (cur.step == N) {
55+
bw.write("minigimbob");
56+
return;
57+
}
58+
59+
if (cur.cnt >= K) {
60+
continue;
61+
}
62+
63+
nxt = cur.step + 1;
64+
if (nxt <= N && minCnt[nxt] > cur.cnt + 1) {
65+
minCnt[nxt] = cur.cnt + 1;
66+
q.offer(new Node(nxt, cur.cnt + 1));
67+
}
68+
69+
nxt = cur.step + cur.step / 2;
70+
if (nxt <= N && minCnt[nxt] > cur.cnt + 1) {
71+
minCnt[nxt] = cur.cnt + 1;
72+
q.offer(new Node(nxt, cur.cnt + 1));
73+
}
74+
}
75+
bw.write("water");
76+
}
77+
78+
}
79+
```

0 commit comments

Comments
 (0)