Just a runnable solution
Code\n\nimpl Solution {\n    pub fn minimum_moves(grid: Vec<Vec<i32>>) -> i32 {\n        use std::collections::{HashMap, VecDeque};\n        let n = grid.len();
# Code\n```\nimpl Solution {\n    pub fn minimum_moves(grid: Vec<Vec<i32>>) -> i32 {\n        use std::collections::{HashMap, VecDeque};\n        let n = grid.len();\n        let mut ans = 0;\n        let mut mp = HashMap::<(i32, (i32, i32)), i32>::new();\n        let mut q = VecDeque::new();\n        q.push_back((0, (0, 1)));\n        mp.insert((0, (0, 1)), 1);\n        while !q.is_empty() {\n            let mut m = q.len();\n            while m > 0 {\n                let (pos, (x, y)) = q.pop_front().unwrap();\n                if x == (n - 1) as i32 && y == (n - 1) as i32 && pos == 0 {\n                    return ans;\n                }\n                if pos == 0 {\n                    if y + 1 < n as i32 && grid[x as usize][y as usize + 1] == 0 && mp.get(&(0, (x, y + 1))).is_none() {\n                        q.push_back((0, (x, y + 1)));\n                        mp.insert((0, (x, y + 1)), 1);\n                    }\n                    if x + 1 < n as i32\n                        && grid[x as usize + 1][y as usize] == 0\n                        && grid[x as usize + 1][y as usize - 1] == 0\n                        && mp.get(&(0, (x + 1, y))).is_none()\n                    {\n                        q.push_back((0, (x + 1, y)));\n                        mp.insert((0, (x + 1, y)), 1);\n                    }\n                    if x + 1 < n as i32\n                        && grid[x as usize + 1][y as usize] == 0\n                        && grid[x as usize + 1][y as usize - 1] == 0\n                        && mp.get(&(1, (x + 1, y - 1))).is_none()\n                    {\n                        q.push_back((1, (x + 1, y - 1)));\n                        mp.insert((1, (x + 1, y - 1)), 1);\n                    }\n                } else {\n                    if x + 1 < n as i32 && grid[x as usize + 1][y as usize] == 0 && mp.get(&(1, (x + 1, y))).is_none() {\n                        q.push_back((1, (x + 1, y)));\n                        mp.insert((1, (x + 1, y)), 1);\n                    }\n                    if y + 1 < n as i32\n                        && grid[x as usize][y as usize + 1] == 0\n                        && grid[x as usize - 1][y as usize + 1] == 0\n                        && mp.get(&(1, (x, y + 1))).is_none()\n                    {\n                        q.push_back((1, (x, y + 1)));\n                        mp.insert((1, (x, y + 1)), 1);\n                    }\n                    if y + 1 < n as i32\n                        && grid[x as usize][y as usize + 1] == 0\n                        && grid[x as usize - 1][y as usize + 1] == 0\n                        && mp.get(&(0, (x - 1, y + 1))).is_none()\n                    {\n                        q.push_back((0, (x - 1, y + 1)));\n                        mp.insert((0, (x - 1, y + 1)), 1);\n                    }\n                }\n                m -= 1;\n            }\n            ans += 1;\n        }\n        -1\n    }\n}\n\n```
['Rust']