Skip to content

Commit ddb7099

Browse files
committed
[Silver I] Title: 미로 탐색, Time: 164 ms, Memory: 12524 KB -BaekjoonHub
1 parent 079e3bd commit ddb7099

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

백준/Silver/2178. 미로 탐색/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 34088 KB, 시간: 76 ms
7+
메모리: 12524 KB, 시간: 164 ms
88

99
### 분류
1010

11-
너비 우선 탐색, 그래프 이론, 그래프 탐색
11+
그래프 이론, 그래프 탐색, 너비 우선 탐색, 격자 그래프
1212

1313
### 제출 일자
1414

15-
2024년 4월 9일 14:12:38
15+
2026년 2월 11일 12:47:26
1616

1717
### 문제 설명
1818

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* /dev/stdin */
2+
let fs = require("fs");
3+
let input = fs
4+
.readFileSync("/dev/stdin")
5+
.toString()
6+
.split("\n")
7+
.map((x) => x.replaceAll("\r", ""));
8+
9+
const [N, M] = input[0].split(" ").map(Number);
10+
11+
const maze = input.slice(1).map((x) => x.split("").map(Number));
12+
const visited = Array.from({ length: N }, () => Array(M).fill(false));
13+
const queue = [];
14+
queue.push([0, 0, 1]);
15+
visited[0][0] = true;
16+
17+
while (queue.length > 0) {
18+
const [x, y, dist] = queue.shift();
19+
if (x === N - 1 && y === M - 1) {
20+
console.log(dist);
21+
break;
22+
}
23+
//상
24+
if (x - 1 >= 0 && !visited[x - 1][y] && maze[x - 1][y] === 1) {
25+
visited[x - 1][y] = true;
26+
queue.push([x - 1, y, dist + 1]);
27+
}
28+
29+
//우
30+
if (y + 1 < M && !visited[x][y + 1] && maze[x][y + 1] === 1) {
31+
visited[x][y + 1] = true;
32+
queue.push([x, y + 1, dist + 1]);
33+
}
34+
35+
//하
36+
if (x + 1 < N && !visited[x + 1][y] && maze[x + 1][y] === 1) {
37+
visited[x + 1][y] = true;
38+
queue.push([x + 1, y, dist + 1]);
39+
}
40+
//좌
41+
if (y - 1 >= 0 && !visited[x][y - 1] && maze[x][y - 1] === 1) {
42+
visited[x][y - 1] = true;
43+
queue.push([x, y - 1, dist + 1]);
44+
}
45+
}

0 commit comments

Comments
 (0)