From 0d1e15bf43af8d9250c96be91073e018d43c30cf Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Sat, 22 Nov 2025 09:00:20 +0700 Subject: [PATCH] =?UTF-8?q?[20251122]=20BOJ=20/=20G5=20/=20=EA=B0=90?= =?UTF-8?q?=EC=8B=9C=20=ED=94=BC=ED=95=98=EA=B8=B0=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \355\224\274\355\225\230\352\270\260.md" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "JHLEE325/202511/22 BOJ G5 \352\260\220\354\213\234 \355\224\274\355\225\230\352\270\260.md" diff --git "a/JHLEE325/202511/22 BOJ G5 \352\260\220\354\213\234 \355\224\274\355\225\230\352\270\260.md" "b/JHLEE325/202511/22 BOJ G5 \352\260\220\354\213\234 \355\224\274\355\225\230\352\270\260.md" new file mode 100644 index 00000000..c8c27c0d --- /dev/null +++ "b/JHLEE325/202511/22 BOJ G5 \352\260\220\354\213\234 \355\224\274\355\225\230\352\270\260.md" @@ -0,0 +1,81 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static char[][] map; + static List blank = new ArrayList<>(); + static List teacher = new ArrayList<>(); + static boolean found = false; // 성공 여부 + + static int[] dr = {-1, 1, 0, 0}; + static int[] dc = {0, 0, -1, 1}; + + public static void main(String[] args) throws Exception { + + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + map = new char[N][N]; + + for (int i = 0; i < N; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + map[i][j] = st.nextToken().charAt(0); + + if (map[i][j] == 'X') blank.add(new int[]{i, j}); + if (map[i][j] == 'T') teacher.add(new int[]{i, j}); + } + } + + dfs(0, 0); + + System.out.println(found ? "YES" : "NO"); + } + + static void dfs(int idx, int cnt) { + if (found) return; + + if (cnt == 3) { + if (check()) found = true; + return; + } + + if (idx >= blank.size()) return; + + int r = blank.get(idx)[0]; + int c = blank.get(idx)[1]; + + map[r][c] = 'O'; + dfs(idx + 1, cnt + 1); + + map[r][c] = 'X'; + dfs(idx + 1, cnt); + } + + static boolean check() { + for (int[] t : teacher) { + int tr = t[0]; + int tc = t[1]; + + for (int d = 0; d < 4; d++) { + int nr = tr; + int nc = tc; + + while (true) { + nr += dr[d]; + nc += dc[d]; + + if (nr < 0 || nc < 0 || nr >= N || nc >= N) break; + + if (map[nr][nc] == 'O') break; + if (map[nr][nc] == 'S') return false; + } + } + } + return true; + } +} +```