同一份代码
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 5e2 + 10, dx[] = {1, -1}, dy[] = {0, 0, 1, -1};
queue<int> qx, qy;
bool vis[maxn][maxn];
int n, m, a, b, tx, ty, nx, ny, dis[maxn][maxn];
int main() {
scanf("%d %d %d %d", &n, &m, &a, &b);
while (a--) {
scanf("%d %d", &tx, &ty);
vis[tx][ty] = true;
qx.push(tx), qy.push(ty);
}
while (qx.size()) {
tx = qx.front();
ty = qy.front();
for (int i = 0; i <= 3; i++) {
nx = tx + dx[i];
ny = ty + dy[i];
if (nx < 1 || nx > n || ny < 1 || ny > m || vis[nx][ny]) continue;
vis[nx][ny] = true;
qx.push(nx), qy.push(ny);
dis[nx][ny] = dis[tx][ty] + 1;
}
qx.pop();
qy.pop();
}
while (b--) {
scanf("%d %d", &tx, &ty);
printf("%d\n", dis[tx][ty]);
}
return 0;
}
使用C++98/C++98 O2/C++14(GCC9) O2交就全WA,下载数据.out的是个这玩意:ਰਰਰਰਰਲਰਲਰਰਰਰਰਰਰਰਰਰਰਰਰਰਰਰਰਰਰਰਰਰ
什么玩意啊