Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions kmj-99/202509/16 횡단보도.md
Original file line number Diff line number Diff line change
@@ -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<List<Node>> crossWalk;
private static long[] distance;
static class Node implements Comparable<Node>{
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<Node> 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<Node>());
}
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]);
}
}


```
127 changes: 127 additions & 0 deletions kmj-99/202509/18428.md
Original file line number Diff line number Diff line change
@@ -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<Node> 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<N; i++){
st = new StringTokenizer(br.readLine());
for(int j=0; j<N; j++){
map[i][j] = st.nextToken();
if(map[i][j].equals("S")){
student.add(new Node(i, j));
}
}
}

dfs(0);

bw.write("NO");
bw.flush();
bw.close();
}

static public void dfs(int depth){
if(depth == 3){
bfs();
return;
}

for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
if(map[i][j].equals("X")){
map[i][j] = "O";
dfs(depth+1);
map[i][j] = "X";
}
}
}

}

private static void bfs() {

Queue<Node> 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;
}

}


```