From 5a628ad552c66e6e6dc1506f2010965a7d09120c Mon Sep 17 00:00:00 2001 From: oncsr Date: Mon, 3 Feb 2025 17:25:11 +0900 Subject: [PATCH] =?UTF-8?q?[20250203]=20BOJ=20/=20=EA=B3=A8=EB=93=9C2=20/?= =?UTF-8?q?=20=EB=93=B1=EC=82=B0=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../03 BOJ G2 \353\223\261\354\202\260.md" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "khj20006/202502/03 BOJ G2 \353\223\261\354\202\260.md" diff --git "a/khj20006/202502/03 BOJ G2 \353\223\261\354\202\260.md" "b/khj20006/202502/03 BOJ G2 \353\223\261\354\202\260.md" new file mode 100644 index 00000000..d58cf067 --- /dev/null +++ "b/khj20006/202502/03 BOJ G2 \353\223\261\354\202\260.md" @@ -0,0 +1,73 @@ +```java + +import java.util.*; +import java.io.*; + +class Main { + + // IO field + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + static long nextLong() {return Long.parseLong(st.nextToken());} + static void bwEnd() throws Exception {bw.flush();bw.close();} + + // Additional field + + + public static void main(String[] args) throws Exception { + + int[] dx = {1,0,-1,0}; + int[] dy = {0,1,0,-1}; + + nextLine(); + int N = nextInt(), M = nextInt(), T = nextInt(), D = nextInt(); + int[][] A = new int[N][M]; + for(int i=0;i PQ = new PriorityQueue<>((a,b) -> a[0]-b[0]); + dist[0][0][A[0][0]] = 0; + PQ.offer(new int[] {0,0,0,A[0][0]}); + while(!PQ.isEmpty()) { + int[] now = PQ.poll(); + int t = now[0], x = now[1], y = now[2], a = now[3]; + if(t > dist[x][y][a]) continue; + 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) continue; + if(Math.abs(A[x][y] - A[xx][yy]) > T) continue; + int aa = Math.max(a, A[xx][yy]); + int v = Math.max(1, A[xx][yy] - A[x][y]); + if(dist[xx][yy][aa] > t + v*v) { + dist[xx][yy][aa] = t+v*v; + PQ.offer(new int[] {t+v*v,xx,yy,aa}); + } + } + } + for(int i=51;i>=0;i--) { + if(dist[0][0][i] <= D) { + bw.write(i+"\n"); + bwEnd(); + return; + } + } + + bwEnd(); + } + +} + +```