Skip to content

Commit 91cbe27

Browse files
committed
boj 1261
1 parent dfa06d6 commit 91cbe27

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

BOJ/1261.알고스팟/dosimpact.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import sys
2+
import math
3+
from typing import *
4+
import itertools
5+
from collections import deque
6+
7+
8+
# 알고스팟
9+
# N,M 빈방 - 가중치 0, 벽 1
10+
11+
M, N = map(int, input().split())
12+
graph: List[List[int]] = [list(map(int, list(input()))) for _ in range(N)]
13+
check: List[List[int]] = [[-1 for _ in range(M)] for _ in range(N)]
14+
15+
16+
def inRange(x: int, y: int):
17+
return x >= 0 and y >= 0 and x < N and y < M
18+
19+
20+
dx, dy = [0, 0, 1, -1], [1, -1, 0, 0]
21+
q = deque()
22+
q.append((0, 0)) # 0,0 으로 들어옴
23+
check[0][0] = 0
24+
25+
while q:
26+
x, y = q.popleft()
27+
for k in range(4):
28+
nx, ny = x+dx[k], y+dy[k]
29+
if inRange(nx, ny) and check[nx][ny] == -1:
30+
if graph[nx][ny] == 0:
31+
check[nx][ny] = check[x][y]
32+
q.appendleft((nx, ny))
33+
continue
34+
if graph[nx][ny] == 1:
35+
check[nx][ny] = check[x][y] + 1
36+
q.append((nx, ny))
37+
continue
38+
39+
print(check[N-1][M-1])

0 commit comments

Comments
 (0)