From e99ea301d37da650b31258be19b4ca198782ca55 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 30 Sep 2025 20:47:58 +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=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= 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" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 "suyeun84/202509/30 BOJ G4 \353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.md" diff --git "a/suyeun84/202509/30 BOJ G4 \353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.md" "b/suyeun84/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..e6fef432 --- /dev/null +++ "b/suyeun84/202509/30 BOJ G4 \353\256\244\355\203\210\353\246\254\354\212\244\355\201\254.md" @@ -0,0 +1,57 @@ +```java +import java.io.*; +import java.util.*; + +public class boj12869 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception { st = new StringTokenizer(br.readLine()); } + static int nextInt() { return Integer.parseInt(st.nextToken()); } + + public static void main(String[] args) throws Exception { + nextLine(); + int N = nextInt(); + + int[] hp = new int[3]; + Arrays.fill(hp, 0); + + nextLine(); + for (int i = 0; i < N; i++) hp[i] = nextInt(); + + boolean[][][] visited = new boolean[61][61][61]; + Queue q = new ArrayDeque<>(); + q.offer(new int[]{hp[0], hp[1], hp[2]}); + visited[hp[0]][hp[1]][hp[2]] = true; + + int[][] dmg = { + {9,3,1},{9,1,3}, + {3,9,1},{3,1,9}, + {1,9,3},{1,3,9} + }; + + int attacks = 0; + while (!q.isEmpty()) { + int sz = q.size(); + for (int s = 0; s < sz; s++) { + int[] cur = q.poll(); + int a = cur[0], b = cur[1], c = cur[2]; + if (a == 0 && b == 0 && c == 0) { + System.out.println(attacks); + return; + } + for (int[] d : dmg) { + int na = Math.max(0, a - d[0]); + int nb = Math.max(0, b - d[1]); + int nc = Math.max(0, c - d[2]); + if (!visited[na][nb][nc]) { + visited[na][nb][nc] = true; + q.offer(new int[]{na, nb, nc}); + } + } + } + attacks++; + } + System.out.println(attacks); + } +} +```