Skip to content

Commit 7976f49

Browse files
committed
[level 2] Title: 게임 맵 최단거리, Time: 10.45 ms, Memory: 9.48 MB -BaekjoonHub
1 parent b7d9831 commit 7976f49

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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

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

55
### 성능 요약
66

7-
메모리: 10.4 MB, 시간: 11.30 ms
7+
메모리: 9.48 MB, 시간: 10.45 ms
88

99
### 구분
1010

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

1717
### 제출 일자
1818

19-
2025년 03월 07일 17:35:12
19+
2025년 12월 31일 13:49:06
2020

2121
### 문제 설명
2222

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22

33
def solution(maps):
44
n, m = len(maps), len(maps[0])
5-
dx = [-1, 1, 0, 0]
6-
dy = [0, 0, -1, 1]
7-
85
visited = [[False] * m for _ in range(n)]
96
visited[0][0] = True
107

11-
q = deque([(0, 0, 1)])
8+
q = deque([(1, 0, 0)])
9+
dx = [-1, 1, 0, 0]
10+
dy = [0, 0, -1, 1]
1211

1312
while q:
14-
x, y, dist = q.popleft()
13+
cnt, x, y = q.popleft()
1514
if x == n-1 and y == m-1:
16-
return dist
15+
return cnt
1716

1817
for i in range(4):
1918
nx = x + dx[i]
2019
ny = y + dy[i]
20+
2121
if 0 <= nx < n and 0 <= ny < m and not visited[nx][ny] and maps[nx][ny] == 1:
22-
q.append((nx, ny, dist+1))
22+
q.append((cnt + 1, nx, ny))
2323
visited[nx][ny] = True
24+
25+
2426
return -1

0 commit comments

Comments
 (0)