蒟蒻求助大佬 WA + TLE + MLE + RE
  • 板块P1141 01迷宫
  • 楼主fansj
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/8/2 18:47
  • 上次更新2023/11/3 06:18:00
查看原帖
蒟蒻求助大佬 WA + TLE + MLE + RE
751264
fansj楼主2023/8/2 18:47
# include <iostream>
# include <stdio.h>
# include <cstring>
# define MaxN 1000
# define MaxM 100000
# define f(i, n) for(i = 0; i < n; i++)

using namespace std;

void dfs(int, int);

bool map[MaxN][MaxM], b[MaxN][MaxM];
int n, m, ans, sx, sy;
char c;

int main()
{
  memset(b, false, sizeof(b));
  cin >> n >> m;
  int i, j;
  f (i, n)
    f (j, m)
    {
      cin >> c;
      map[i][j] = c - '0';
    }
  f (i, m)
  {
    memset(b, false, sizeof(b));
    cin >> sx >> sy;
    dfs(sx - 1, sy - 1);
    cout << ans << '\n';
    ans = 0;
  }
  return 0;
}

void dfs(int x, int y)
{
  if (x < 0 || x >= n || y < 0 || y >= m || b[x][y])
    return;
  ans++;
  b[x][y] = true;
  if (map[x][y - 1] == !map[x][y])
  {
    dfs(x, y - 1);
  }
  if (map[x][y + 1] == !map[x][y])
  {
    dfs(x, y + 1);
  }
  if (map[x - 1][y] == !map[x][y])
  {
    dfs(x - 1, y);
  }
  if (map[x + 1][y] == !map[x][y])
  {
    dfs(x + 1, y);
  }
}

蒟蒻求助各位神犇,DFS WA + TLE + MLE + RE

2023/8/2 18:47
加载中...