From a7f963e7ad61420d8d4bb4346fc4a7fd925410ad Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Mon, 29 Sep 2025 23:38:10 +0900 Subject: [PATCH] =?UTF-8?q?[20250929]=20BOJ=20/=20G5=20/=20=EC=8B=AD?= =?UTF-8?q?=EC=9E=90=EB=92=A4=EC=A7=91=EA=B8=B0=20/=20=EC=9D=B4=EC=9D=B8?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20\353\222\244\354\247\221\352\270\260.md" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "LiiNi-coder/202509/29 BOJ \354\213\255\354\236\220\353\222\244\354\247\221\352\270\260.md" diff --git "a/LiiNi-coder/202509/29 BOJ \354\213\255\354\236\220\353\222\244\354\247\221\352\270\260.md" "b/LiiNi-coder/202509/29 BOJ \354\213\255\354\236\220\353\222\244\354\247\221\352\270\260.md" new file mode 100644 index 00000000..706365c0 --- /dev/null +++ "b/LiiNi-coder/202509/29 BOJ \354\213\255\354\236\220\353\222\244\354\247\221\352\270\260.md" @@ -0,0 +1,74 @@ +```java +import java.io.*; +import java.util.*; +import java.util.stream.IntStream; + +public class Main { + private static int N = 3; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int T = Integer.parseInt(br.readLine()); + while(T-- > 0){ + var map = 0; + for(int r = 0; r < N; r++) { + char[] cs = br.readLine().toCharArray(); + for (int c = 0; c < N; c++) { + if (cs[c] == '*') + map += 1<<(N*r + c); + } + } + System.out.println(solve(map)); + } + br.close(); + } + + private static int solve(int initialMap) { + boolean[] visited = new boolean[512]; + Deque q = new ArrayDeque<>(); + q.add(new int[]{initialMap, 0}); + visited[initialMap] = true; + while(!q.isEmpty()){ + int[] temp = q.poll(); + int map = temp[0], count = temp[1]; + if(map == 0){ + return count; + } + for(int di: IntStream.range(0, 9).toArray()){ + int nextMap = toggle(map, di); + if(visited[nextMap]) continue; + visited[nextMap] = true; + q.add(new int[]{nextMap, count+1}); + } + } + return -1; + } + + private static int toggle(int map, int black1d) { + List masks = new ArrayList<>(); + masks.add(black1d); + if(black1d % N == 0){ + masks.add(black1d + 1); + }else if(black1d % N == 1){ + masks.add(black1d + 1); + masks.add(black1d-1); + }else{ + masks.add(black1d-1); + } + + if(black1d / N == 0){ + masks.add(black1d + N); + }else if(black1d / N == 1){ + masks.add(black1d - N); + masks.add(black1d + N); + }else{ + masks.add(black1d-N); + } + + for(int mask: masks){ + map ^= 1<