From 2538f8d53f195eee8573846a4a003d569b437d61 Mon Sep 17 00:00:00 2001 From: oncsr Date: Fri, 29 Aug 2025 21:47:05 +0900 Subject: [PATCH] =?UTF-8?q?[20250829]=20BOJ=20/=20P5=20/=20=EB=B0=94?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=83=80=EC=9D=98=20=ED=9E=98=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\203\200\354\235\230 \355\236\230.md" | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 "khj20006/202508/29 BOJ P5 \353\260\224\353\246\254\354\212\244\355\203\200\354\235\230 \355\236\230.md" diff --git "a/khj20006/202508/29 BOJ P5 \353\260\224\353\246\254\354\212\244\355\203\200\354\235\230 \355\236\230.md" "b/khj20006/202508/29 BOJ P5 \353\260\224\353\246\254\354\212\244\355\203\200\354\235\230 \355\236\230.md" new file mode 100644 index 00000000..df893fad --- /dev/null +++ "b/khj20006/202508/29 BOJ P5 \353\260\224\353\246\254\354\212\244\355\203\200\354\235\230 \355\236\230.md" @@ -0,0 +1,135 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final int INF = (int)1e9 + 7; + static final int[] dx = {1,0,-1,0}; + static final int[] dy = {0,1,0,-1}; + + static int N, M; + static boolean[][] wall; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + M = io.nextInt(); + wall = new boolean[N][M]; + for(int i=0;i=0;j--) { + right[i][j] = Math.min(right[i][j+1], to[i][j] + j); + } + } + + int[][] up = new int[N][M]; + for(int j=0;j=0;i--) { + up[i][j] = Math.min(up[i+1][j], to[i][j] + i); + } + } + + int ans = INF; + for(int i=0;i q = new ArrayDeque<>(); + q.offer(new int[]{a,b,0}); + vis[a][b] = true; + while(!q.isEmpty()) { + int[] cur = q.poll(); + int x = cur[0], y = cur[1], t = cur[2]; + res[x][y] = t; + for(int i=0;i<4;i++) { + int xx = x+dx[i], yy = y+dy[i]; + if(xx<0 || xx>=N || yy<0 || yy>=M || vis[xx][yy]) continue; + if(wall[xx][yy]) { + if(can) { + res[xx][yy] = t+1; + vis[xx][yy] = true; + } + continue; + } + q.offer(new int[]{xx,yy,t+1}); + vis[xx][yy] = true; + } + } + return res; + } + +} +```