diff --git "a/JHLEE325/202507/23 BOJ G4 \354\210\250\353\260\224\352\274\255\354\247\210 2.md" "b/JHLEE325/202507/23 BOJ G4 \354\210\250\353\260\224\352\274\255\354\247\210 2.md" new file mode 100644 index 00000000..f5f974f6 --- /dev/null +++ "b/JHLEE325/202507/23 BOJ G4 \354\210\250\353\260\224\352\274\255\354\247\210 2.md" @@ -0,0 +1,62 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int[] time = new int[100001]; + static int[] count = new int[100001]; + static int n, k; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + n = Integer.parseInt(st.nextToken()); + k = Integer.parseInt(st.nextToken()); + + if (n == k) { + System.out.println(0); + System.out.println(1); + return; + } + + Queue q = new LinkedList<>(); + q.add(n); + time[n] = 0; + count[n] = 1; + + while (!q.isEmpty()) { + int cur = q.poll(); + + for (int j = 0; j < 3; j++) { + int next = 0; + switch (j) { + case 0: + next = cur - 1; + break; + case 1: + next = cur + 1; + break; + case 2: + next = cur * 2; + break; + } + + if (next < 0 || next > 100000) continue; + + if (time[next] == 0 && next != n) { + time[next] = time[cur] + 1; + count[next] = count[cur]; + q.add(next); + } else if (time[next] == time[cur] + 1) { + count[next] += count[cur]; + } + } + } + + System.out.println(time[k]); + System.out.println(count[k]); + } +} + +```