Skip to content

Commit 4971e31

Browse files
committed
[level 2] Title: 게임 맵 최단거리, Time: 6.29 ms, Memory: 11.3 MB -BaekjoonHub
1 parent f5ba845 commit 4971e31

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

프로그래머스/2/1844. 게임 맵 최단거리/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# [level 2] 게임 맵 최단거리 - 1844
22

3-
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/1844?language=java)
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/1844?language=python3)
44

55
### 성능 요약
66

7-
메모리: 57.9 MB, 시간: 3.46 ms
7+
메모리: 11.3 MB, 시간: 6.29 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2026년 05월 08일 19:53:54
19+
2026년 07월 01일 22:36:25
2020

2121
### 문제 설명
2222

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
from collections import deque
22

33
def solution(maps):
4-
n, m = len(maps), len(maps[0])
4+
q = deque([(0, 0, 1)])
5+
n = len(maps)
6+
m = len(maps[0])
7+
dx = [1, -1, 0, 0]
8+
dy = [0, 0, 1, -1]
59
visited = [[False] * m for _ in range(n)]
610
visited[0][0] = True
711

8-
q = deque([(1, 0, 0)])
9-
dx = [-1, 1, 0, 0]
10-
dy = [0, 0, -1, 1]
11-
1212
while q:
13-
cnt, x, y = q.popleft()
13+
x, y, total = q.popleft()
14+
1415
if x == n-1 and y == m-1:
15-
return cnt
16+
return total
1617

1718
for i in range(4):
1819
nx = x + dx[i]
1920
ny = y + dy[i]
2021

21-
if 0 <= nx < n and 0 <= ny < m and not visited[nx][ny] and maps[nx][ny] == 1:
22-
q.append((cnt + 1, nx, ny))
22+
if 0 <= nx and nx < n and 0 <= ny and ny < m and not visited[nx][ny] and maps[nx][ny] == 1:
23+
q.append((nx, ny, total+1))
2324
visited[nx][ny] = True
2425

25-
2626
return -1

0 commit comments

Comments
 (0)