2
def minimumMoves(self, grid: List[List[int]]) -> int:3
queue, vis, n = [(0, 1, 0, 0)], {}, len(grid)5
x, y, pos, moves = queue.pop(0)6
if x == y == n - 1 and pos == 0:9
if y + 1 < n and grid[x][y + 1] == 0 and (x, y + 1, 0) not in vis:10
vis[(x, y + 1, 0)] = True11
queue.append((x, y + 1, 0, moves + 1))13
if x + 1 < n and grid[x + 1][y - 1] == 0 and grid[x + 1][y] == 0:14
if (x + 1, y - 1, 1) not in vis:15
vis[(x + 1, y - 1, 1)] = True16
queue.append((x + 1, y - 1, 1, moves + 1))17
if (x + 1, y, 0) not in vis:18
vis[(x + 1, y, 0)] = True19
queue.append((x + 1, y, 0, moves + 1))21
if x + 1 < n and grid[x + 1][y] == 0 and (x + 1, y, 1) not in vis:22
vis[(x + 1, y, 1)] = True23
queue.append((x + 1, y, 1, moves + 1))24
if y + 1 < n and grid[x - 1][y + 1] == grid[x][y + 1] == 0:25
if (x - 1, y + 1, 0) not in vis:26
vis[(x - 1, y + 1, 0)] = True27
queue.append((x - 1, y + 1, 0, moves + 1))28
if (x, y + 1, 1) not in vis:29
vis[(x, y + 1, 1)] = True30
queue.append((x, y + 1, 1, moves + 1))