From ddb2f8b53416ba3208c5dce1a39d26d1f99cbcfa Mon Sep 17 00:00:00 2001 From: oncsr Date: Sun, 10 Aug 2025 14:57:23 +0900 Subject: [PATCH] =?UTF-8?q?[20250810]=20BOJ=20/=20P4=20/=20=EB=AC=B4?= =?UTF-8?q?=EC=9E=90=EB=B9=84=ED=95=9C=20=EC=B5=9C=EB=8B=A8=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=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 --- ...4\353\213\250 \352\262\275\353\241\234.md" | 167 ++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 "khj20006/202508/10 BOJ P4 \353\254\264\354\236\220\353\271\204\355\225\234 \354\265\234\353\213\250 \352\262\275\353\241\234.md" diff --git "a/khj20006/202508/10 BOJ P4 \353\254\264\354\236\220\353\271\204\355\225\234 \354\265\234\353\213\250 \352\262\275\353\241\234.md" "b/khj20006/202508/10 BOJ P4 \353\254\264\354\236\220\353\271\204\355\225\234 \354\265\234\353\213\250 \352\262\275\353\241\234.md" new file mode 100644 index 00000000..16916ae9 --- /dev/null +++ "b/khj20006/202508/10 BOJ P4 \353\254\264\354\236\220\353\271\204\355\225\234 \354\265\234\353\213\250 \352\262\275\353\241\234.md" @@ -0,0 +1,167 @@ +```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 class Node { + int idx, val; + Node(int idx, int val) { + this.idx = idx; + this.val = val; + } + + @Override + public boolean equals(Object o) { + if (o == null || getClass() != o.getClass()) + return false; + Node node = (Node)o; + return idx == node.idx && val == node.val; + } + + @Override + public int hashCode() { + return Objects.hash(idx, val); + } + } + + static final long INF = (long)1e18 + 7; + + static int N, K; + static int[][] x, y; + static int[] xpos, ypos; + static List[] z; + static int[] rz; + static PriorityQueue pq; + static long[] dist; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + static void init() throws Exception { + + N = io.nextInt(); + K = io.nextInt(); + x = new int[N][]; + y = new int[N][]; + z = new List[K]; + rz = new int[N]; + for(int i=0;i(); + for(int i=0;i a[1]==b[1] ? a[0]-b[0] : a[1]-b[1]); + Arrays.sort(y, (a,b) -> a[1]==b[1] ? a[0]-b[0] : a[1]-b[1]); + for(int i=0;i a.val==b.val ? a.idx-b.idx : a.val-b.val); + + xpos = new int[N]; + for(int i=0;i((a,b) -> Long.compare(a[0],b[0])); + pq.offer(new long[]{0,0}); + while(!pq.isEmpty()) { + long[] cur = pq.poll(); + int n = (int)cur[1]; + long d = cur[0]; + if(d > dist[n]) continue; + z[rz[n]%K].remove(new Node(n, rz[n])); + int X = xpos[n]; + if(X>0) process(x[X-1][0], d + x[X][1]-x[X-1][1]); + if(X0) process(y[Y-1][0], d + y[Y][1]-y[Y-1][1]); + if(Y d) { + dist[next] = d; + pq.offer(new long[]{dist[next], next}); + } + } + + + +} +```