From 430f3e35a05699faa504cb57c28c4b983c8cd4ab Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 10 Oct 2025 23:09:15 +0900 Subject: [PATCH] =?UTF-8?q?[20251010]=20PGM=20/=20LV2=20/=20=EA=B1=B0?= =?UTF-8?q?=EB=A6=AC=EB=91=90=EA=B8=B0=20=ED=99=95=EC=9D=B8=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\354\235\270\355\225\230\352\270\260.md" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "suyeun84/202510/10 PGM LV2 \352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.md" diff --git "a/suyeun84/202510/10 PGM LV2 \352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.md" "b/suyeun84/202510/10 PGM LV2 \352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.md" new file mode 100644 index 00000000..c27758c3 --- /dev/null +++ "b/suyeun84/202510/10 PGM LV2 \352\261\260\353\246\254\353\221\220\352\270\260 \355\231\225\354\235\270\355\225\230\352\270\260.md" @@ -0,0 +1,64 @@ +```java +import java.util.*; + +class Solution { + static int[] dx = {-1, 1, 0, 0}; + static int[] dy = {0, 0, -1, 1}; + static List answer = new ArrayList<>(); + + public List solution(String[][] places) { + for (String[] place : places) { + String[] p = place; + boolean isfalse = false; + outer:for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + if (p[i].charAt(j) == 'P') { + if(!bfs(i, j, p)) { + System.out.println(i + " " + j); + isfalse = true; + break outer; + } + } + } + } + if (isfalse) { + answer.add(0); + } else { + answer.add(1); + } + } + return answer; + } + + static boolean bfs(int i, int j, String[] p) { + Queue queue = new ArrayDeque<>(); + queue.offer(new int[]{i, j}); + boolean[][] visited = new boolean[5][5]; + visited[i][j] = true; + + while(!queue.isEmpty()) { + int[] cur = queue.poll(); + for (int n = 0; n < 4; n++) { + int nx = cur[0] + dx[n]; + int ny = cur[1] + dy[n]; + + if (nx < 0 || ny < 0 || nx >= 5 || ny >= 5) continue; + + if (!visited[nx][ny]) { + int d = Math.abs(nx - i) + Math.abs(ny - j); + + if (d <= 2 && p[nx].charAt(ny) == 'P') { + return false; + } else if(p[nx].charAt(ny) == 'O' && d <= 2) { + System.out.println(nx + " " + ny); + visited[nx][ny] = true; + queue.offer(new int[]{nx, ny}); + } + } + } + } + System.out.println(" "); + return true; + } +} +```