From 8c9f865ab676cafb86a2569be91645f738c0ba2a Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Sun, 15 Jun 2025 22:19:51 +0900 Subject: [PATCH] =?UTF-8?q?[20250615]=20BOJ=20/=20G4=20/=20=EC=88=A8?= =?UTF-8?q?=EB=B0=94=EA=BC=AD=EC=A7=88=202=20/=20=EC=84=A4=EC=A7=84?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\260\224\352\274\255\354\247\210 2.md" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "Seol-JY/202506/15 BOJ G4 \354\210\250\353\260\224\352\274\255\354\247\210 2.md" diff --git "a/Seol-JY/202506/15 BOJ G4 \354\210\250\353\260\224\352\274\255\354\247\210 2.md" "b/Seol-JY/202506/15 BOJ G4 \354\210\250\353\260\224\352\274\255\354\247\210 2.md" new file mode 100644 index 00000000..131f39f9 --- /dev/null +++ "b/Seol-JY/202506/15 BOJ G4 \354\210\250\353\260\224\352\274\255\354\247\210 2.md" @@ -0,0 +1,54 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int[] visited = new int[100001]; + static int minTime = Integer.MAX_VALUE; + static int count = 0; + static int start, target; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + start = Integer.parseInt(st.nextToken()); + target = Integer.parseInt(st.nextToken()); + + bfs(); + + System.out.println(minTime); + System.out.println(count); + } + + public static void bfs() { + Deque queue = new ArrayDeque<>(); + queue.add(start); + visited[start] = 1; + + while (!queue.isEmpty()) { + int current = queue.poll(); + int time = visited[current]; + + if (current == target) { + if (time - 1 < minTime) { + minTime = time - 1; + count = 1; + } else if (time - 1 == minTime) { + count++; + } + continue; + } + + for (int next : new int[]{current - 1, current + 1, current * 2}) { + if (next < 0 || next > 100000) continue; + + if (visited[next] == 0 || visited[next] == time + 1) { + visited[next] = time + 1; + queue.add(next); + } + } + } + } +} + +```