#include #include #include #include #include using namespace std; const int INF = INT_MAX >> 1; int dx[] = {1, 2, 2, 1, -1, -2, -2, -1}; int dy[] = {2, 1, -1, -2, -2, -1, 1, 2}; bool check(int bx, int by, int x, int y) { return (x >= 0 && x < bx && y >= 0 && y < by); } int main() { int n, m, x, y; cin >> n >> m >> x >> y; vector> mp(n, vector(m, INF)); x--; y--; // ת»»³É 0-based queue> q; q.push({x, y, 0}); mp[x][y] = 0; while (!q.empty()) { auto [qx, qy, path] = q.front(); q.pop(); for (int i = 0; i < 8; i++) { int nx = qx + dx[i]; int ny = qy + dy[i]; if (check(n, m, nx, ny) && mp[nx][ny] == INF) { mp[nx][ny] = path + 1; q.push({nx, ny, path + 1}); } } } for (auto &row : mp) { for (auto v : row) { cout << (v == INF ? -1 : v) << " "; } cout << "\n"; } return 0; }