4
set<vector<int>> visited;5
bool candown(vector<vector<int>> &grid, int x, int y, bool hor) {7
if (x + 2 < n && grid[x + 1][y] == 0 && grid[x + 2][y] == 0 &&8
!visited.count({x + 1, y, hor})) {12
if (x + 1 < n && y + 1 < n && grid[x + 1][y] == 0 && grid[x + 1][y + 1] == 0 &&13
!visited.count({x + 1, y, hor})) {21
bool canright(vector<vector<int>> &grid, int x, int y, bool hor) {23
if (y + 2 < n && grid[x][y + 1] == 0 && grid[x][y + 2] == 0 &&24
!visited.count({x, y + 1, hor})) {28
if (y + 1 < n && x + 1 < n && grid[x][y + 1] == 0 && grid[x + 1][y + 1] == 0 &&29
!visited.count({x, y + 1, hor})) {37
bool canrot(vector<vector<int>> &grid, int x, int y, bool hor) {39
if (y + 1 < n && x + 1 < n && grid[x + 1][y] == 0 && grid[x + 1][y + 1] == 0 &&40
!visited.count({x, y, !hor})) {44
if (x + 1 < n && y + 1 < n && grid[x][y + 1] == 0 && grid[x + 1][y + 1] == 0 &&45
!visited.count({x, y, !hor})) {52
int minimumMoves(vector<vector<int>> &grid) {53
queue<array<int, 3>> q;62
if (visited.count({a[0], a[1], a[2]})) {65
visited.insert({a[0], a[1], a[2]});68
if (x == n - 1 && y == n - 2 && a[2] == 1) {71
if (candown(grid, x, y, a[2])) {72
q.push({x + 1, y, a[2]});74
if (canrot(grid, x, y, a[2])) {75
q.push({x, y, !a[2]});77
if (canright(grid, x, y, a[2])) {78
q.push({x, y + 1, a[2]});