diff --git "a/kmj-99/202509/16 \355\232\241\353\213\250\353\263\264\353\217\204.md" "b/kmj-99/202509/16 \355\232\241\353\213\250\353\263\264\353\217\204.md" new file mode 100644 index 0000000..d933562 --- /dev/null +++ "b/kmj-99/202509/16 \355\232\241\353\213\250\353\263\264\353\217\204.md" @@ -0,0 +1,78 @@ +```java + + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + private static int N, M; + private static List> crossWalk; + private static long[] distance; + static class Node implements Comparable{ + int index; + long cost; + Node(int index, long cost) { + this.index = index; + this.cost = cost; + } + + @Override + public int compareTo(Node o) { + return Long.compare(this.cost, o.cost); + } + } + private static void dijkstra() { + PriorityQueue queue = new PriorityQueue<>(); + queue.offer(new Node(1, 0)); + distance[1] = 0; + + while(!queue.isEmpty()) { + Node currentNode = queue.poll(); + if (currentNode.cost > distance[currentNode.index]) + continue; + for (Node next :crossWalk.get(currentNode.index)) { + int nextIndex = next.index; + long nextCost; + if (currentNode.cost <= next.cost) { + nextCost = next.cost + 1; + } else { + // 모듈러 연산 + nextCost = ((long) Math.ceil(((double)currentNode.cost-next.cost)/M)) * M + next.cost + 1; + } + if (nextCost < distance[nextIndex]) { + distance[nextIndex] = nextCost; + queue.offer(new Node(nextIndex, nextCost)); + } + } + } + } + public static void main(String[] args) throws Exception { + StringTokenizer st; + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + + distance = new long[N+1]; + Arrays.fill(distance, Long.MAX_VALUE); + + crossWalk = new ArrayList<>(); + for (int i = 0; i <= N; i++) { + crossWalk.add(new ArrayList()); + } + for (int i = 0; i < M; i++) { + st = new StringTokenizer(br.readLine()); + int u = Integer.parseInt(st.nextToken()); + int v = Integer.parseInt(st.nextToken()); + crossWalk.get(u).add(new Node(v, i)); + crossWalk.get(v).add(new Node(u, i)); + } + dijkstra(); + System.out.println(distance[N]); + } +} + + +``` diff --git a/kmj-99/202509/18428.md b/kmj-99/202509/18428.md new file mode 100644 index 0000000..2d97c60 --- /dev/null +++ b/kmj-99/202509/18428.md @@ -0,0 +1,127 @@ +```java + +import java.io.*; +import java.util.*; + + +public class Main { + static class Node{ + int x; + int y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + } + + static final int[] dx = {0, 0, 1, -1}; + static final int[] dy = {1, -1, 0, 0}; + static ArrayList student = new ArrayList<>(); + static int N; + static String[][] map; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + map = new String[N][N]; + + for(int i=0; i q = new LinkedList<>(); + String[][] copyMap = new String[N][N]; + boolean[][] check = new boolean[N][N]; + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + copyMap[i][j] = map[i][j]; + } + } + + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (copyMap[i][j].equals("T")) { + q.add(new Node(i, j)); + check[i][j] = true; + } + } + } + + while (!q.isEmpty()) { + Node now = q.poll(); + int x = now.x; + int y = now.y; + + for (int k = 0; k < 4; k++) { + int nx = x + dx[k]; + int ny = y + dy[k]; + + while(0 <= nx && nx < N && 0 <= ny && ny < N) { + if (!copyMap[nx][ny].equals("O")) { + check[nx][ny] = true; + nx += dx[k]; + ny += dy[k]; + }else{ + break; + } + } + } + } + if(catchStudent(check)){ + System.out.println("YES"); + System.exit(0); + } + } + + private static boolean catchStudent(boolean[][] check) { + + for (Node node : student) { + if (check[node.x][node.y] == true) { + return false; + } + } + return true; + } + +} + + +```