#3 #4 #5 #6 #7 #8 #9 全部MLE,请dalao能帮我改改吗?
#include <bits/stdc++.h>
using namespace std;
typedef long long l;
l n, m, m_x, m_y, ans[405][405];
l dx[8] = {-2, -2, 2, 2, 1, -1, 1, -1};
l dy[8] = {-1, 1, -1, 1, 2, -2, -2, 2};
bool visited[405][405];
void bfs(l x, l y) {
memset(ans, -1, sizeof(ans));
queue<pair<l, l>> q;
q.push(pair<l, l>{x, y});
ans[x][y] = 0;
while (!q.empty()) {
pair<l, l> front = q.front();
visited[front.first][front.second] = true;
for (int i = 0; i < 8; i ++) {
l tx, ty;
tx = front.first + dx[i];
ty = front.second + dy[i];
if (tx > 0 && tx <= n && ty > 0 && ty <= m) {
if (!visited[tx][ty]) {
ans[tx][ty] = ans[front.first][front.second] + 1;
q.push(pair<l, l>{tx, ty});
}
}
}
q.pop();
}
}
int main () {
cin >> n >> m >> m_x >> m_y;
bfs(m_x, m_y);
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) {
printf("%-4d", ans[i][j]);
}
cout << endl;
}
return 0;
}