[Python] 카카오 2020 인턴쉽 - 경주로 건설 (BFS)
from collections import deque def solution(board): ans = float('inf') n = len(board) dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] # (nx, ny, d) : cost visit = {(0,0,0):0, (0,0,1):0, (0,0,2) : 0, (0,0,3):0} que = deque() #초기값. x, y, dir = -1 , cost que.append((0,0,-1,0)) #BFS while que: x, y, dir, cost = que.popleft() for d in range(4): nx = x + dx[d] ny = y + dy[d] #이동 가능하면 (범위내이고 board[nx][ny]가 0이면) i..
2020. 8. 16.