0分求调
查看原帖
0分求调
985457
caokang楼主2025/7/25 20:49

全部MLE

评测记录

#include <bits/stdc++.h>
using namespace std;

int n, m, isOk;
char a[105][105];
bool vis[105][105];

struct Pos {
    int x, y;
};
void bfs() {
    queue<Pos> q;
    Pos tmp;
    tmp.x = 1, tmp.y = 1;
    q.push(tmp);
    while(!q.empty()) {
        Pos now =q.front(); 
        q.pop(); 
        int x = now.x, y = now.y;
        if(x < 1 || x > n) continue; 
        if(y < 1 || y > m) continue; 
        if(a[x][y] == '#') continue; 

        if(vis[x][y]) continue; 
        vis[x][y] == 1; 
        if(x == n && y == m){ 
            isOk = true; return;
        }

        Pos nxt;
        nxt.x = x - 1, nxt.y = y; 
        q.push(nxt); 

        nxt.x = x+1, nxt.y = y;
        q.push(nxt);

        nxt.x = x, nxt.y = y+1;
        q.push(nxt);

        nxt.x = x, nxt.y = y-1;
        q.push(nxt);
    }
}

int main() {
    cin >> n >> m; 
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> a[i][j];

    bfs();

    if(isOk)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}
2025/7/25 20:49
加载中...