1号和3号测试点AC,2号和6号WA,其余TLE,求大佬帮帮忙
#include<bits/stdc++.h>
using namespace std;
const int N = 409;
int n,m,x,y;
int a[N][N];
bool check[N][N];
//队列
int h = 0,t = 0;
int q[N][2];
int step = 0;
int dx[8] = {-1,1,-1,1,2,2,-2,-2};
int dy[8] = {-2,-2,2,2,-1,1,1,-1};
void bfs1(int x,int y){
check[x][y] = true;
for(int i=0;i<8;i++){
int tx = x + dx[i];
int ty = y + dy[i];
if(tx>n || tx<1 || ty>m|| ty<1 || check[tx][ty]==true)continue;
q[t][0] = tx;
q[t++][1] = ty;
check[tx][ty] = true;
}
}
int main(){
cin >> n >> m >> x >> y;
for(int i = 1; i<= n;i++){
for(int j = 1; j<=m;j++){
a[i][j] = -1;
check[i][j] = false;
}
}
q[t][0] = x;
q[t++][1] = y;
int tt = t;
a[1][1] = 0;
while(h <= t){
int x = q[h][0];
int y = q[h++][1];
bfs1(x,y);
a[x][y] = step;
if(h == tt){
step++;
tt = t;
}
}
for(int i = 1; i<= n;i++){
for(int j = 1; j<=m;j++){
printf("%-5d",a[i][j]);
}
cout << endl;
}
return 0;
}