File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
1616
1717### 제출 일자
1818
19- 2026년 05월 08일 19:53:54
19+ 2026년 07월 01일 22:36:25
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 11from collections import deque
22
33def 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
You can’t perform that action at this time.
0 commit comments