#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 solve (int i, int j, int n) { queue> s; vector first = {0,0,0}; s.push(first); vector a; int visited[n][n] = { {0} }; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) visited[i][j] = 0; visited[0][0] = 1; while (s.size() != 0) { a = s.front(); s.pop(); vector nn1 = { a[0]+i, a[0]+i, a[0]+j, a[0]+j, a[0]-i, a[0]-i, a[0]-j, a[0]-j}; vector nn2 = { a[1]+j, a[1]-j, a[1]+i, a[1]-i, a[1]+j, a[1]-j, a[1]+i, a[1]-i}; for (int kk = 0; kk< 8; kk++) { if (nn1[kk] == n-1 && nn2[kk] == n-1) return a[2]+1; if (nn1[kk] > n-1 || nn2[kk] > n-1 || nn1[kk] < 0 || nn2[kk] < 0) continue; // cout << visited[nn1[kk]][nn2[kk]] << nn1[kk] << nn2[kk] << "\n"; if(visited[nn1[kk]][nn2[kk]]) continue; //cout << nn1[kk] << nn2[kk]<< a[2]+1 << "\n"; vector nn = {nn1[kk], nn2[kk], a[2]+1}; s.push(nn); visited[nn1[kk]][nn2[kk]] = 1; } } return -1; } int main(){ int n; cin >> n; int solution[n-1][n-1]; for (int i=0; i < n-1; i++) { for (int j=0; j < n-1; j++) { if (i > j) solution[i][j] = solution[j][i]; else solution[i][j] = solve (i+1, j+1, n); cout << solution[i][j] << " "; }; cout << "\n"; } // your code goes here return 0; }