#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct Node { int r,c; Node(int _r, int _c): r(_r), c(_c) {} }; int minDist(int n, int a, int b, vector>& grid) { int i,j; vector oneMove(2); vector> moves(8,oneMove); int m[]={-1,1}; for (int i=0;i<2;i++) for(int j=0;j<2;j++) { oneMove[0]=m[i]*a; oneMove[1]=m[j]*b; moves.push_back(oneMove); swap(oneMove[0],oneMove[1]); moves.push_back(oneMove); } for (i=0;i nodeQ; nodeQ.push(cur); while (nodeQ.empty()==false) { cur = nodeQ.front(); nodeQ.pop(); for (int i=0;i=n || newNode.c<0||newNode.c>=n) continue; if ( grid[newNode.r][newNode.c] > grid[cur.r][cur.c]+1) { grid[newNode.r][newNode.c]=grid[cur.r][cur.c]+1; if (newNode.r==n-1&&newNode.c==n-1) return grid[n-1][n-1]; nodeQ.push(newNode); } } } return -1; } int main(){ int n; cin >> n; // your code goes here int a,b; vector oneRow(n); vector< vector > grid(n,oneRow); for (a=1;a1) cout<<" "; cout<