alexjercan/bugnet huggingface dataset:
Problem p00711 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, P> PP;

//-----------------------------------------------------------------------------

int sx, sy, h, w;
string fld[20];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

int bfs() {
  bool used[h][w];
  REP(i, h) REP(j, w) used[i][j] = false;
  int cnt = 1;
  queue<P> q;
  used[sy][sx] = true;
  q.push(P(sx, sy));
  while (!q.empty()) {
    P p = q.front();
    q.pop();
    REP(i, 4) {
      int nx = p.fi + dx[i], ny = p.se + dy[i];
      if (nx < 0 || nx >= w || ny < 0 || ny >= h || used[ny][nx] ||
          fld[ny][nx] == '#')
        continue;
      used[ny][nx] = true;
      cnt++;
      q.push(P(nx, ny));
    }
  }
  return cnt;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (true) {
    cin >> w >> h;
    if (w == 0)
      break;
    REP(i, h) {
      cin >> fld[i];
      REP(j, w) if (fld[i][j] == '@') sx = j, sy = i;
    }
    cout << bfs() << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, P> PP;

//-----------------------------------------------------------------------------

int sx, sy, h, w;
string fld[20];
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

int bfs() {
  bool used[h][w];
  REP(i, h) REP(j, w) used[i][j] = false;
  int cnt = 1;
  queue<P> q;
  used[sy][sx] = true;
  q.push(P(sx, sy));
  while (!q.empty()) {
    P p = q.front();
    q.pop();
    REP(i, 4) {
      int nx = p.fi + dx[i], ny = p.se + dy[i];
      if (nx < 0 || nx >= w || ny < 0 || ny >= h || used[ny][nx] ||
          fld[ny][nx] == '#')
        continue;
      used[ny][nx] = true;
      cnt++;
      q.push(P(nx, ny));
    }
  }
  return cnt;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (true) {
    cin >> w >> h;
    REP(i, h) {
      cin >> fld[i];
      REP(j, w) if (fld[i][j] == '@') sx = j, sy = i;
    }
    cout << bfs() << endl;
  }

  return 0;
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

#include <array>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

int height, width;
int sx, sy;

void bfs(vector<vector<char>> &field) {
  int ans = 1;
  array<int, 4> dx = {0, 0, 1, -1};
  array<int, 4> dy = {1, -1, 0, 0};

  queue<pii> p;
  p.push({sx, sy});

  while (!p.empty()) {
    pii q = p.front();
    p.pop();

    //??????
    int cx = q.first;
    int cy = q.second;

    for (int i = 0; i < 4; ++i) {
      int nx = cx + dx.at(i);
      int ny = cy + dy.at(i);

      if (nx >= 0 && nx < width && ny >= 0 && ny < height &&
          field.at(ny).at(nx) == '.') {

        ans++;
        field.at(ny).at(nx) = '#';
        p.push({nx, ny});
      }
    }
  }

  std::cout << ans << std::endl;
}

int main() {
  while (cin >> width >> height) {
    if (height == 0 && width == 0)
      break;

    vector<vector<char>> field(height, vector<char>(width));

    for (int y = 0; y < height; ++y) {
      for (int x = 0; x < width; ++x) {
        cin >> field.at(y).at(x);

        if (field.at(y).at(x) == '@') {
          sx = x;
          sy = y;
        }
      }
    }

    bfs(field);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <array>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

int height, width;
int sx, sy;
int ans = 0;
array<int, 4> dx = {0, 0, 1, -1};
array<int, 4> dy = {1, -1, 0, 0};

void bfs(vector<vector<char>> &field) {
  queue<pii> p;
  p.push({sx, sy});

  while (!p.empty()) {
    pii q = p.front();
    p.pop();

    //??????
    int cx = q.first;
    int cy = q.second;

    for (int i = 0; i < 4; ++i) {
      int nx = cx + dx.at(i);
      int ny = cy + dy.at(i);

      if (nx >= 0 && nx < width && ny >= 0 && ny < height &&
          field.at(ny).at(nx) == '.') {

        ans++;
        p.push({nx, ny});
      }
    }
  }

  std::cout << ans << std::endl;
}

int main() {
  while (cin >> height >> width) {
    if (height == 0 && width == 0)
      break;

    ans = 0;

    vector<vector<char>> field(height, vector<char>(width));

    for (int y = 0; y < height; ++y) {
      for (int x = 0; x < width; ++x) {
        cin >> field.at(y).at(x);

        if (field.at(y).at(x) == '@') {
          sx = x;
          sy = y;
        }
      }
    }

    bfs(field);
  }

  return 0;
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <iostream>
#define REP(i, l, n) for (int i = l; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define MAX 21
int ans, baseX, baseY;
int w, h;
char tile[MAX][MAX];
void seek(int x, int y);
using namespace std;
int main() {
  while (1) {
    cin >> w;
    cin >> h;
    if (w == 0 && h == 0)
      return 0;
    rep(i, h) {
      rep(j, w) {
        cin >> tile[i][j];
        if (tile[i][j] == '@') {
          baseX = i;
          baseY = j;
        }
      }
      tile[i][w] = '#';
    }
    rep(i, w) tile[h][i] = '#';
    ans = 1;
    seek(baseX, baseY);
    cout << ans << endl;
  }
  return 0;
}

void seek(int x, int y) {
  if (tile[x + 1][y] == '.') {
    tile[x + 1][y] = '#';
    ans++;
    seek(x + 1, y);
  }
  if (tile[x][y + 1] == '.') {
    tile[x][y + 1] = '#';
    ans++;
    seek(x, y + 1);
  }
  if (tile[x - 1][y] == '.') {
    tile[x - 1][y] = '#';
    ans++;
    seek(x - 1, y);
  }
  if (tile[x][y - 1] == '.') {
    tile[x][y - 1] = '#';
    ans++;
    seek(x, y - 1);
  }
}

Error: 0

Fixed submission:

#include <cassert>
#include <iostream>
#define REP(i, l, n) for (int i = l; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define MAX 20
int ans, baseX, baseY;
int w, h;
char tile[MAX][MAX];
void seek(int x, int y);
using namespace std;
int main() {
  while (1) {
    cin >> w;
    cin >> h;
    if (w == 0 && h == 0)
      return 0;
    rep(i, h) {
      rep(j, w) {
        cin >> tile[i][j];
        if (tile[i][j] == '@') {
          baseX = i;
          baseY = j;
        }
      }
      tile[i][w] = '#';
    }
    rep(i, w) tile[h][i] = '#';
    ans = 1;
    seek(baseX, baseY);
    cout << ans << endl;
  }
  return 0;
}

void seek(int x, int y) {
  if (tile[x + 1][y] == '.') {
    tile[x + 1][y] = '#';
    ans++;
    seek(x + 1, y);
  }
  if (tile[x][y + 1] == '.') {
    tile[x][y + 1] = '#';
    ans++;
    seek(x, y + 1);
  }
  if (tile[x - 1][y] == '.') {
    tile[x - 1][y] = '#';
    ans++;
    seek(x - 1, y);
  }
  if (tile[x][y - 1] == '.') {
    tile[x][y - 1] = '#';
    ans++;
    seek(x, y - 1);
  }
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MOD 1000000007
#define ADD(X, Y) ((X) = ((X) + (Y) % MOD) % MOD)
typedef long long i64;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int, int> pi;
int dd[] = {0, 1, 0, -1, 0};

int main() {
  while (true) {
    int W, H;
    cin >> W >> H;
    if (W == 0 && H == 0)
      break;

    char C[30][30];
    int B[30][30];

    int sx = -1;
    int sy = -1;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> C[i][j];
        B[i][j] = 0;
        if (C[i][j] == '@') {
          sy = i;
          sx = j;
        }
      }
    }

    queue<pi> Q;
    Q.push(pi(sy, sx));
    B[sy][sx] = 1;
    int ans = 1;
    while (!Q.empty()) {
      int ty = Q.front().first;
      int tx = Q.front().second;
      Q.pop();

      for (int r = 0; r < 4; r++) {
        int y = ty + dd[r];
        int x = tx + dd[r + 1];
        if (y < 0 || y >= H || x < 0 || x >= W)
          continue;
        if (C[y][x] == '#')
          continue;
        if (B[y][x])
          continue;
        ans++;
        B[y][x] = 1;
        Q.push(pi(y, x));
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MOD 1000000007
#define ADD(X, Y) ((X) = ((X) + (Y) % MOD) % MOD)
typedef long long i64;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int, int> pi;
int dd[] = {0, 1, 0, -1};

int main() {
  while (true) {
    int W, H;
    cin >> W >> H;
    if (W == 0 && H == 0)
      break;

    char C[30][30];
    int B[30][30];

    int sx = -1;
    int sy = -1;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> C[i][j];
        B[i][j] = 0;
        if (C[i][j] == '@') {
          sy = i;
          sx = j;
        }
      }
    }

    queue<pi> Q;
    Q.push(make_pair(sy, sx));
    B[sy][sx] = 1;
    int ans = 1;
    while (!Q.empty()) {
      int ty = Q.front().first;
      int tx = Q.front().second;
      Q.pop();

      for (int r = 0; r < 4; r++) {
        int y = ty + dd[r];
        int x = tx + dd[r + 1];
        if (y < 0 || y >= H || x < 0 || x >= W)
          continue;
        if (C[y][x] == '#')
          continue;
        if (B[y][x])
          continue;
        ans++;
        B[y][x] = 1;
        Q.push(make_pair(y, x));
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <vector>

using namespace std;
vector<int> ans;
typedef pair<int, int> P;

int main() {
  int W, H;
  cin >> W >> H;
  int tate[4] = {0, 1, 0, -1};
  int yoko[4] = {1, 0, -1, 0};
  while (W) {
    int count = 0;
    queue<P> zahyou;
    vector<vector<int>> room(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        char a;
        cin >> a;
        if (a == '.')
          room[i][j] = 1;
        else if (a == '@') {
          zahyou.push(P(i, j));
          room[i][j] = 1;
        } else
          room[i][j] = 0;
      }
    }
    while (zahyou.size()) {
      pair<int, int> now = zahyou.front();
      zahyou.pop();
      if (room[now.first][now.second] == 1) {
        count++;
        room[now.first][now.second] = 0;
        for (int i = 0; i < 4; i++) {
          if (now.first + tate[i] >= 0 && now.first + tate[i] < H &&
              now.second + yoko[i] >= 0 && now.second + yoko[i] < W &&
              room[now.first + tate[i]][now.second + yoko[i]] == 1)
            zahyou.push(P(now.first + tate[i], now.second + yoko[i]));
        }
      }
    }
    ans.push_back(count);
    cin >> W >> H;
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] << endl;
}


Error: -11

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>

using namespace std;
vector<int> ans;
typedef pair<int, int> P;

int main() {
  int W, H;
  cin >> W >> H;
  int tate[4] = {0, 1, 0, -1};
  int yoko[4] = {1, 0, -1, 0};
  while (W) {
    int count = 0;
    queue<P> zahyou;
    vector<vector<int>> room(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        char a;
        cin >> a;
        if (a == '.')
          room[i][j] = 1;
        else if (a == '@') {
          zahyou.push(P(i, j));
          room[i][j] = 1;
        } else
          room[i][j] = 0;
      }
    }
    while (zahyou.size()) {
      pair<int, int> now = zahyou.front();
      zahyou.pop();
      if (room[now.first][now.second] == 1) {
        count++;
        room[now.first][now.second] = 0;
        for (int i = 0; i < 4; i++) {
          zahyou.push(P(now.first + tate[i], now.second + yoko[i]));
        }
      }
    }
    ans.push_back(count);
    cin >> W >> H;
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] << endl;
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define ll long long

using namespace std;

int W, H;

char r[1000][1000];

int sh, sw;
int bnum = 0;

int solve(int i, int j) {
  int ans = 0;

  if (i < 0 || H <= i || j < 0 || W <= j)
    return 0;
  if (r[i][j] == '#') {
    return 0;
  }
  ans = 1;
  r[i][j] = '#';
  ans += solve(i - 1, j);
  ans += solve(i + 1, j);
  ans += solve(i, j - 1);
  ans += solve(i, j + 1);

  return ans;
}

int main() {

  while (1) {
    scanf("%d %d", &W, &H);
    if (W == 0 && H == 0)
      break;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> r[i][j];
        if (r[i][j] == '@') {
          sh = i;
          sw = j;
          r[i][j] = '.';
        }
      }
    }
    cout << solve(sh, sw) << endl;
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>

#define ll long long

using namespace std;

int W, H;

char r[1000][1000];

int sh, sw;
int bnum = 0;

int c[1000][1000] = {};

int solve(int i, int j) {
  int ans = 0;

  if (i < 0 || H <= i || j < 0 || W <= j)
    return 0;
  if (r[i][j] == '#') {
    return 0;
  }

  if (i - 1 >= 0) {
    ans += solve(i - 1, j);
  }

  if (i + 1 < H) {
    ans += solve(i + 1, j);
  }
  if (j - 1 >= 0) {
    ans += solve(i, j - 1);
  }
  if (j + 1 < W) {
    ans += solve(i, j + 1);
  }
  return ans;
}

int main() {

  while (1) {
    scanf("%d %d", &W, &H);
    if (W == 0 && H == 0)
      break;

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> r[i][j];
        if (r[i][j] == '@') {
          sh = i;
          sw = j;
          r[i][j] = '.';
        }
      }
    }
    cout << solve(sh, sw) << endl;
  }
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
char n[100][100];
int k[100][100], l[100][100], sum, H, W, i, j, m, s;
#define A(B, C)                                                                \\
  if (k[B][C] != 1) {                                                          \\
    l[B][C] = 1;                                                               \\
  }
main() {
  while (true) {
    s = 0;
    memset(l, 0, sizeof(l));
    cin >> W >> H;
    if (W == 0) {
      break;
    }
    for (i = 1; i <= H; i++) {
      for (j = 1; j <= W; j++) {
        cin >> n[i][j];
        if (n[i][j] == '.') {
          k[i][j] = 0;
        } else if (n[i][j] == '@') {
          k[i][j] = 2;
          l[i][j] = 1;
        } else {
          k[i][j] = 1;
        }
      }
    }
    for (i = 0; i < 2500; i++) {
      for (j = 1; j <= H; j++) {
        for (m = 1; m <= W; m++) {
          if (l[j][m] == 1) {
            A(j - 1, m);
            A(j + 1, m);
            A(j, m - 1);
            A(j, m + 1);
          }
        }
      }
    }
    for (j = 1; j <= H; j++) {
      for (m = 1; m <= W; m++) {
        if (l[j][m] == 1) {
          s++;
        }
      }
    }
    cout << s << endl;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
char n[100][100];
int k[100][100], l[100][100], sum, H, W, i, j, m, s;
#define A(B, C)                                                                \\
  if (k[B][C] != 1) {                                                          \\
    l[B][C] = 1;                                                               \\
  }
int main() {
  while (true) {
    s = 0;
    memset(l, 0, sizeof(l));
    std::cin >> W >> H;
    if (W == 0) {
      break;
    }
    for (i = 1; i <= H; i++) {
      for (j = 1; j <= W; j++) {
        std::cin >> n[i][j];
        if (n[i][j] == '.') {
          k[i][j] = 0;
        } else if (n[i][j] == '@') {
          k[i][j] = 2;
          l[i][j] = 1;
        } else {
          k[i][j] = 1;
        }
      }
    }
    for (i = 0; i < 2500; i++) {
      for (j = 1; j <= H; j++) {
        for (m = 1; m <= W; m++) {
          if (l[j][m] == 1) {
            A(j - 1, m);
            A(j + 1, m);
            A(j, m - 1);
            A(j, m + 1);
          }
        }
      }
    }
    for (j = 1; j <= H; j++) {
      for (m = 1; m <= W; m++) {
        if (l[j][m] == 1) {
          s++;
        }
      }
    }
    scanf("%d\\n", s);
  }
}
Problem p00711 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int check(int j) {
  if (j == 2 || j == 4 || j == 3)
    return j;
  else
    return 3;
}
int main() {
  int board[22][22];
  int w, h;
  char t;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i <= 21; i++) {
      for (int j = 0; j <= 21; j++) {
        board[j][i] = 4;
      }
    } // initialization
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        cin >> t;
        if (t == '.')
          board[j][i] = 1;
        else if (t == '#')
          board[j][i] = 2;
        else
          board[j][i] = 3;
      }
    } // input end
    int cmem = 2000;
    int c = 0;
    while (cmem - c != 0) {
      cmem = c;
      for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
          if (board[j][i] == 3) {
            board[j - 1][i] = check(board[j - 1][i]);
            board[j + 1][i] = check(board[j + 1][i]);
            board[j][i - 1] = check(board[j][i - 1]);
            board[j][i + 1] = check(board[j][i + 1]);
          }
        }
      }
      c = 0;
      for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
          if (board[j][i] == 3)
            c += 1;
        }
      }
    }

    cout << c << endl;
  } // while loop end
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int check(int j) {
  if (j == 2 || j == 4 || j == 3)
    return j;
  else
    return 3;
}
int main() {
  int board[22][22];
  int w, h;
  char t;
  while (1) {
    cin >> w >> h;
    for (int i = 0; i <= 21; i++) {
      for (int j = 0; j <= 21; j++) {
        board[j][i] = 4;
      }
    } // initialization
    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        cin >> t;
        if (t == '.')
          board[j][i] = 1;
        else if (t == '#')
          board[j][i] = 2;
        else
          board[j][i] = 3;
      }
    } // input end
    int cmem = 2000;
    int c = 0;
    while (cmem - c != 0) {
      cmem = c;
      for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
          if (board[j][i] == 3) {
            board[j - 1][i] = check(board[j - 1][i]);
            board[j + 1][i] = check(board[j + 1][i]);
            board[j][i - 1] = check(board[j][i - 1]);
            board[j][i + 1] = check(board[j][i + 1]);
          }
        }
      }
      c = 0;
      for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
          if (board[j][i] == 3)
            c += 1;
        }
      }
    }

    cout << c << endl;
  } // while loop end
  return 0;
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int H, W, count = 0;
char **map;
bool **isCount;

bool valid(int x, int y) {
  return x <= (W - 1) && x >= 0 && y <= (H - 1) && y >= 0;
}

void bfs(int x, int y) {
  if (valid(x, y) && map[y][x] != '#' && !isCount[y][x]) {
    count++;
    isCount[y][x] = true;
    for (int i = 0; i < 4; i++)
      bfs(x + dx[i], y + dy[i]);
  }
  /*int D[100];
  for(int i=0;i<100;i++)
    D[i]=-1;
  queue<int>Q;
  Q.push(src);
  D[src]=0;
  while(!Q.empty())
    {
      int cur=Q.front();
      Q.pop();
       for(int dst=0;dst<n;dst++)
        {
          if(M[cur][dst]==1&&D[dst]==-1)
            {
              D[dst]=D[cur]+1;
              Q.push(dst);
            }
    }
    }
    for(int i=0;i<n;i++)
        cout<<i+1<<' '<<D[i]<<endl;
        */
}

int main() {
  int x, y;
  cin >> W >> H;
  while (W != 0 && H != 0) {
    isCount = new bool *[H];
    map = new char *[H];
    for (int i = 0; i < H; i++) {
      isCount[i] = new bool[W];
      map[i] = new char[W];
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++)
        isCount[i][j] = false;
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> map[i][j];
        if (map[i][j] == '@') {
          x = j;
          y = i;
        }
      }
    }
    bfs(x, y);
    cout << count << endl;
    delete map;
    delete isCount;
    cin >> W >> H;
    count = 0;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>

using namespace std;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int H, W, count = 0;
char **map;
bool **isCount;

bool valid(int x, int y) {
  return x <= (W - 1) && x >= 0 && y <= (H - 1) && y >= 0;
}

void bfs(int x, int y) {
  if (valid(x, y) && map[y][x] != '#' && !isCount[y][x]) {
    count++;
    isCount[y][x] = true;
    for (int i = 0; i < 4; i++)
      bfs(x + dx[i], y + dy[i]);
  }
  /*int D[100];
  for(int i=0;i<100;i++)
    D[i]=-1;
  queue<int>Q;
  Q.push(src);
  D[src]=0;
  while(!Q.empty())
    {
      int cur=Q.front();
      Q.pop();
       for(int dst=0;dst<n;dst++)
        {
          if(M[cur][dst]==1&&D[dst]==-1)
            {
              D[dst]=D[cur]+1;
              Q.push(dst);
            }
    }
    }
    for(int i=0;i<n;i++)
        cout<<i+1<<' '<<D[i]<<endl;
        */
}

int main() {
  int x, y;
  cin >> W >> H;
  while (W != 0 && H != 0) {
    isCount = new bool *[H];
    map = new char *[H];
    for (int i = 0; i < H; i++) {
      isCount[i] = new bool[W];
      map[i] = new char[W];
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; i < W; j++)
        isCount[i][j] = false;
    }
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> map[i][j];
        if (map[i][j] == '@') {
          x = j;
          y = i;
        }
      }
    }
    bfs(x, y);
    cout << count << endl;
    delete map;
    delete isCount;
    cin >> W >> H;
  }
  return 0;
}