From 8f851b9d9d1f525fb2cd02d1181ec49077105445 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Sat, 12 Jul 2025 23:46:12 +0900 Subject: [PATCH] =?UTF-8?q?[20250712]=20BOJ=20/=20G5=20/=20=ED=86=A0?= =?UTF-8?q?=EB=A7=88=ED=86=A0=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...J \355\206\240\353\247\210\355\206\240.md" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "LiiNi-coder/202507/12 BOJ \355\206\240\353\247\210\355\206\240.md" diff --git "a/LiiNi-coder/202507/12 BOJ \355\206\240\353\247\210\355\206\240.md" "b/LiiNi-coder/202507/12 BOJ \355\206\240\353\247\210\355\206\240.md" new file mode 100644 index 00000000..24309088 --- /dev/null +++ "b/LiiNi-coder/202507/12 BOJ \355\206\240\353\247\210\355\206\240.md" @@ -0,0 +1,84 @@ +```java +import java.awt.Point; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.HashMap; +import java.util.HashSet; +import java.util.StringTokenizer; + +public class B7576 { + private static BufferedReader br; + private static ArrayDeque q; + private static StringTokenizer st; + private static HashSet wall_tomato_set; + private static int[][] drdcs = { + {1, 0}, + {0, -1}, + {-1, 0}, + {0, 1} + }; + + private static class IntAndPoint{ + Point p; int level; + public IntAndPoint(Point p, int level) { + this.p = p; + this.level = level; + } + } + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + + //입력 + int n, m; + String[] temp = br.readLine().split(" "); + m = Integer.parseInt(temp[0]); + n = Integer.parseInt(temp[1]); + q = new ArrayDeque(); + wall_tomato_set = new HashSet(); + for(int r=0; r= n || next_p.y <0 || next_p.y >= m) { + continue; + } + // 벽인지와 토마토인지 확인 + if(wall_tomato_set.contains(next_p)) + continue; + q.addLast(new IntAndPoint(next_p, level+1)); + } + } + + // 만약 벽 또는 토마토의 개수가 n*m개수와 다르면 불가능 + if(wall_tomato_set.size() != n*m) { + System.out.println(-1); + }else { + System.out.println(max_level); + } + br.close(); + } + +} +```