얼렁뚱땅 백준 문제풀이

[백준 문제풀이] 얼렁뚱땅 2178번 미로탐색 풀이

MOSTAR 2022. 3. 29. 18:38

dfs, bfs 다 까먹어서 다시 보고있는데

난 진짜 다 까먹었을 줄은 몰랐다

진짜 돌덩어리다

 

https://www.acmicpc.net/problem/2178

 

import sys
from collections import deque

n,m = map(int,sys.stdin.readline().split())
array = [(list(map(int,input()))) for i in range(n)]

queue = deque()

dx = [1,-1,0,0]
dy = [0,0,1,-1]

queue.append([0,0])
result = 0

while queue :
	x,y = queue.popleft()
	for i in range(4) :
		nx = x + dx[i]
		ny = y + dy[i]
		if 0<=nx<n and 0<=ny<m :
			if array[nx][ny] == 1 :
				array[nx][ny] = array[x][y] + 1
				queue.append([nx,ny])

print(array[n-1][m-1])

 

느낀점

의문을 가지지말자 외우자