From bacaab71cdfcbf29163391427288aeb01183f07d Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Thu, 17 Jul 2025 22:12:51 +0900 Subject: [PATCH] =?UTF-8?q?[20250717]=20BOJ=20/=20G1=20/=20=EB=B0=B0?= =?UTF-8?q?=EC=97=B4=20=EC=A0=95=EB=A0=AC=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\227\264 \354\240\225\353\240\254.md" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "lkhyun/202507/17 BOJ G1 \353\260\260\354\227\264 \354\240\225\353\240\254.md" diff --git "a/lkhyun/202507/17 BOJ G1 \353\260\260\354\227\264 \354\240\225\353\240\254.md" "b/lkhyun/202507/17 BOJ G1 \353\260\260\354\227\264 \354\240\225\353\240\254.md" new file mode 100644 index 00000000..937bffd7 --- /dev/null +++ "b/lkhyun/202507/17 BOJ G1 \353\260\260\354\227\264 \354\240\225\353\240\254.md" @@ -0,0 +1,70 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,M; + static int[] arr; + static int[][] manipulation; + static int[] correct; + static int ans = -1; + + public static void main(String[] args) throws Exception { + N = Integer.parseInt(br.readLine()); + arr = new int[N+1]; + + st = new StringTokenizer(br.readLine()); + for (int i = 1; i <= N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + correct = Arrays.copyOf(arr, N+1); + Arrays.sort(correct); + + M = Integer.parseInt(br.readLine()); + manipulation = new int[M][3]; + + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int a = Integer.parseInt(st.nextToken()); + int b = Integer.parseInt(st.nextToken()); + int c = Integer.parseInt(st.nextToken()); + manipulation[i] = new int[]{a,b,c}; + } + + dijkstra(); + + bw.write(ans+""); + bw.close(); + } + static void dijkstra(){ + PriorityQueue pq = new PriorityQueue<>((a,b) -> a[0]-b[0]); + Map dist = new HashMap<>(); + pq.offer(arr); + dist.put(Arrays.toString(Arrays.copyOfRange(arr,1,N+1)),0); + + while (!pq.isEmpty()){ + int[] cur = pq.poll(); + String curString = Arrays.toString(Arrays.copyOfRange(cur,1,N+1)); + + if(dist.get(curString) < cur[0]) continue; + + for(int i = 0; i