为什么会MLE
查看原帖
为什么会MLE
1076328
YHL_RP楼主2024/12/18 19:51
#include<bits/stdc++.h>
using namespace std;

const int N = 1001;
char dt[N][N];
int n, dis[N][N];
int x1, x2, y1s, y2s;
int GoX[4] = {0, -1, 0, 1};
int GoY[4] = {-1, 0, 1, 0};

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> dt[i][j];
		}
	}
	cin >> x1 >> y1s >> x2 >> y2s;
	queue<pair<int, int>> q;
	q.push({x1, y1s});
	dt[x1][y1s] = '1';
	
	while(q.size()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		dt[x][y] = '1';
		for (int i = 0; i < 4; i++) {
			int tx = x + GoX[i];
			int ty = y + GoY[i];
			if (tx <= n && tx >= 1 && ty <= n && ty >= 1 && dt[tx][ty] != '1') {
				q.push({tx, ty});
				dis[tx][ty] = dis[x][y] + 1;
			}
		}
	}
	cout << dis[x2][y2s];
	return 0;
}
2024/12/18 19:51
加载中...