本地过洛谷爆0求调玄关
查看原帖
本地过洛谷爆0求调玄关
1430250
_hud楼主2024/12/19 22:58

为什么本地答案也对(测试点1下载下来试过了)但放到你谷上就全部WA

#include <bits/stdc++.h>
#define __init ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;
#define MAXN 1010
const int mv[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const char mv2[5] = "udlr";
int n, m, ans;
char mp[MAXN][MAXN];
bitset<MAXN> rec[MAXN];
struct point { int x, y; };
vector<point> o;
void dfs(int x, int y) {
    if(x < 1 || x > n || y < 1 || y > m) return;
    if(!rec[x][y]) ans++, rec[x][y] = 1;
    for(int i = 0;i < 4;i++) {
        int nx = x + mv[i][0], ny = y + mv[i][1];
        if(mv2[i] == mp[nx][ny]) dfs(nx, ny);
    }
}
signed main() {
    __init;
    cin >> n >> m;
    for(int i = 1;i <= n;i++) {
        scanf("%s", &mp[i][1]);
        for(int j = 1;j <= m;j++)
            if(mp[i][j] == 'o') 
                o.push_back((point){i, j});
    }
    for(point i : o) dfs(i.x, i.y);
    cout << ans;
    return 0;
}
2024/12/19 22:58
加载中...