황소개발자
백준 1261 파이썬 python : 알고스팟 @@황소처럼 우직하게@@ 화이팅! 본문
반응형
고진감래다
import sys
from collections import deque
input = sys.stdin.readline
w, h = map(int, input().split())
miro = [[] for i in range(h)]
for i in range(h):
ss = input().strip()
for s in ss:
miro[i].append(int(s))
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
ans = 999999999
def bfs(y, x):
q = [[y, x]]
nxtq = []
miro[y][x] = 2
while q:
now = q.pop(0)
for i in range(4):
ny = now[0] + dy[i]
nx = now[1] + dx[i]
if 0 <= ny < h and 0 <= nx < w:
if miro[ny][nx] == 0:
miro[ny][nx] = miro[now[0]][now[1]]
q.append([ny, nx])
elif miro[ny][nx] == 1:
miro[ny][nx] = miro[now[0]][now[1]] + 1
nxtq.append([ny, nx])
if not q:
q = nxtq
nxtq = []
bfs(0, 0)
print(miro[-1][-1] - 2)
반응형
'백준 문제 풀이' 카테고리의 다른 글
백준 3055 파이썬 python : 탈출 @@황소처럼 우직하게@@ 테스트케이스가 놓치고 있는 반례, 메모리초과, 시간초과 해결 (0) | 2020.03.04 |
---|---|
백준 2206 파이썬 python : 벽 부수고 이동하기 @@황소처럼 우직하게@@ 준내신기하네 (0) | 2020.03.03 |
백준 13549 파이썬 python : 숨바꼭질 3 @@황소처럼 우직하게@@끌끌 (0) | 2020.03.03 |
백준 14226 파이썬 python : 이모티콘 @@황소처럼 우직하게@@ 이게무슨.. (0) | 2020.03.03 |
백준 1697 파이썬 python : 숨바꼭질 @@황소처럼 우직하게@@ (0) | 2020.03.03 |
Comments