문제
코드
from collections import deque
import sys
input = sys.stdin.readline
dx = [-2, -2, 0, 0, 2, 2]
dy = [-1, 1, -2, 2, -1, 1]
def bfs(x: int, y: int):
queue = deque()
queue.append([x, y])
visited[x][y] = 1
while queue:
x, y = queue.popleft()
for i in range(6):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < n and 0 <= ny < n and visited[nx][ny] == False:
visited[nx][ny] = visited[x][y] + 1
queue.append([nx, ny])
def move_num(move: int) -> int:
return move - 1
if __name__ == '__main__':
n = int(input())
r1, c1, r2, c2 = list(map(int, input().split()))
visited = [[0] * n for _ in range(n)]
bfs(r1, c1)
print(move_num(visited[r2][c2]))
결과
출처 & 깃허브
boj
github