#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; int N; int row, col; int step[25][25]; int ans[25][25] = {}; #define NDF (-1) void initStep(void) { for (int i = 0; i < 25; i++) { for (int j = 0; j < 25; j++) { step[i][j] = NDF; } } } void dfs(int i, int j, int cost){ if (i >= N || i < 0 || j >= N || j < 0) return; if (step[i][j] == NDF || cost < step[i][j]) { step[i][j] = cost; dfs(i + row, j + col, cost+1); dfs(i + row, j - col, cost+1); dfs(i - row, j + col, cost+1); dfs(i - row, j - col, cost+1); dfs(i + col, j + row, cost+1); dfs(i + col, j - row, cost+1); dfs(i - col, j + row, cost+1); dfs(i - col, j - row, cost+1); } } struct node{ int x, y; int cost; node() {} node(int _x, int _y, int _cost) : x(_x), y(_y), cost(_cost) {} }; int xdir[4] = {1, 1, -1, -1}; int ydir[4] = {1, -1, 1, -1}; void bfs(void){ queue q; q.push(node(0,0,0)); step[0][0] = 0; while(!q.empty()){ node cur = q.front(); q.pop(); if(cur.x < 0 || cur.x >= N || cur.y < 0 || cur.y >= N) continue; if(cur.cost >= step[cur.x][cur.y]) continue; for (int i = 0; i < 4; i++) q.push(node(cur.x + xdir[i]*row, cur.y + ydir[i]*col, cur.cost + 1)); for (int i = 0; i < 4; i++) q.push(node(cur.x + xdir[i]*col, cur.y + ydir[i]*row, cur.cost + 1)); } } int main(){ cin >> N; // your code goes here for (int i = 1; i < N; i++) { for (int j = 1; j < N; j++) { if(ans[i][j] != 0) continue; row = i; col = j; initStep(); dfs(0, 0, 0); ans[j][i] = ans[i][j] = step[N-1][N-1]; //cout << step[N-1][N-1] << " "; } //cout << endl; } for (int i = 1; i < N; i++) { for (int j = 1; j < N; j++) { cout << ans[i][j] << " "; } cout << endl; } return 0; }