From 902046c322d9d4ad0b65e44d2287e313ba1576c4 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Tue, 30 Sep 2025 19:30:55 +0900 Subject: [PATCH] =?UTF-8?q?[20250930]=20BOJ=20/=20G4=20/=20=EB=AE=A4?= =?UTF-8?q?=ED=83=88=EB=A6=AC=EC=8A=A4=ED=81=AC=20/=20=ED=95=9C=EC=A2=85?= =?UTF-8?q?=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...10\353\246\254\354\212\244\355\201\254.md" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "Ukj0ng/202509/30 BOJ G4 \353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.md" diff --git "a/Ukj0ng/202509/30 BOJ G4 \353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.md" "b/Ukj0ng/202509/30 BOJ G4 \353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.md" new file mode 100644 index 00000000..e000cf9f --- /dev/null +++ "b/Ukj0ng/202509/30 BOJ G4 \353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.md" @@ -0,0 +1,64 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final int[] dx = {9, 9, 3, 3, 1, 1}; + private static final int[] dy = {3, 1, 9, 1, 3, 9}; + private static final int[] dz = {1, 3, 1, 9, 9, 3}; + private static Set visited; + private static int[] scv; + private static int N; + public static void main(String[] args) throws IOException { + init(); + int answer = BFS(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + scv = new int[3]; + visited = new HashSet<>(); + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < 3; i++) { + if (N == i) break; + scv[i] = Integer.parseInt(st.nextToken()); + } + } + + private static int BFS() { + Queue q = new ArrayDeque<>(); + int result = 0; + visited.add(scv[0]+","+scv[1]+","+scv[2]); + q.add(new int[]{scv[0], scv[1], scv[2], 0}); + + while (!q.isEmpty()) { + int[] current = q.poll(); + + if (current[0] == 0 && current[1] == 0 && current[2] == 0) { + result = current[3]; + break; + } + + for (int i = 0; i < 6; i++) { + int x = current[0] - dx[i] < 0 ? 0 : current[0] - dx[i]; + int y = current[1] - dy[i] < 0 ? 0 : current[1] - dy[i]; + int z = current[2] - dz[i] < 0 ? 0 : current[2] - dz[i]; + + if (visited.contains(x+","+y+","+z)) continue; + visited.add(x+","+y+","+z); + q.add(new int[]{x, y, z, current[3]+1}); + } + } + + return result; + } +} +```