alexjercan/bugnet huggingface dataset:
Problem p00710 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int yama[51];
  int n, r;
  int tmp[51];

  while (std::cin >> n >> r && (n || r)) {
    int c, p;
    rep(i, n) { yama[i] = n - i; }
    rep(i, r) {
      std::cin >> p >> c;
      rep(j, c) { tmp[j] = yama[p - 1 + j]; }
      rep(k, p - 1) { yama[p - 1 + c - k - 1] = yama[p - 1 - k - 1]; }
      rep(l, c) { yama[l] = tmp[l]; }
    }
    std::cout << yama[0] << std::endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

#define rep(i, m) for (int i = 0; i < m; i++)

int main(void) {

  int n, r;     // 山の枚数、回数
  int p, c;     // 上からの何枚目、枚数
  int n1[50];   // 山
  int temp[50]; // 一時的に保存しておく
  int ans[50];  // 答えを保存しておく
  int j = 0;    // 答えを格納する時に使う

  while (std::cin >> n >> r, n || r) { // n,rを取得０、０でなければループ

    rep(i, n) {
      n1[i] = n - i; // n1[n] = {n,n-1,n-2,.........,1}
    }

    rep(i, r) {

      std::cin >> p >> c; // p,cを取得
      rep(i, c) { temp[i] = n1[p - 1 + i]; }
      rep(i, p - 1) { n1[p - 1 - i + c] = n1[p - 1 - i]; }

      rep(i, c) { n1[i] = temp[i]; }
    }
    ans[j++] = n1[0];
  }

  rep(i, j) { std::cout << ans[i] << std::endl; }

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

#include <stdio.h>

void c_copy(int c_tmp[], int data[], int p, int c, int n) {
  int i = 0;
  for (i = 0; i < c; i++) {
    c_tmp[i] = data[n - p + i - c + 1];
    //    printf("i =%d n=%d n-p+i-c = %d\\n",i,n,n-p+i-c+1);
  }
}

void move(int data[], int p, int c, int n) {
  int i;
  for (i = n - p + 1; i < n; i++) {
    data[i - c] = data[i];
  }
}

void tmp_in(int c_tmp[], int data[], int p, int c, int n) {
  int i;
  for (i = n - c; i < n; i++) {
    data[i] = c_tmp[i - n + c];
  }
}

void print(int data[], int n) {
  for (int i = 0; i < n; i++) {
    printf("%d ", data[i]);
  }
  puts("");
}

int main(void) {
  int data[200];
  int n[1000];
  int r[1000];
  int p[1000][200];
  int c[1000][200];
  int c_tmp[1000][200];
  int i = 0, j = 0;
  int N;

  while (1) {
    scanf("%d", &n[i]);
    scanf("%d", &r[i]);
    if (n[i] == r[i] && n[i] == 0) {
      break;
    }
    for (j = 0; j < r[i]; j++) {
      scanf("%d", &p[i][j]);
      scanf("%d", &c[i][j]);
    }
    i++;
  }
  N = i;

  for (i = 0; i < N; i++) {
    for (j = 0; j < 200; j++) {
      data[j] = j + 1;
    }
    for (j = 0; j < r[i]; j++) {
      // print(data, n[i]);//

      c_copy(c_tmp[i], data, p[i][j], c[i][j], n[i]); //
      // printf("c_copy = ");
      // print(c_tmp[i], n[i]);//

      move(data, p[i][j], c[i][j], n[i]);
      // printf("move\\n");
      // print(data, n[i]);

      tmp_in(c_tmp[i], data, p[i][j], c[i][j], n[i]);
      //    print(data, n[i]);
      // puts("");
    }
    printf("%d\\n", data[n[i] - 1]);
  }

  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

void c_copy(int c_tmp[], int data[], int p, int c, int n) {
  int i = 0;
  for (i = 0; i < c; i++) {
    c_tmp[i] = data[n - p + i - c + 1];
    //    printf("i =%d n=%d n-p+i-c = %d\\n",i,n,n-p+i-c+1);
  }
}

void move(int data[], int p, int c, int n) {
  int i;
  for (i = n - p + 1; i < n; i++) {
    data[i - c] = data[i];
  }
}

void tmp_in(int c_tmp[], int data[], int p, int c, int n) {
  int i;
  for (i = n - c; i < n; i++) {
    data[i] = c_tmp[i - n + c];
  }
}

void print(int data[], int n) {
  for (int i = 0; i < n; i++) {
    printf("%d ", data[i]);
  }
  puts("");
}

int main(void) {
  int data[200];
  int n[100];
  int r[100];
  int p[100][200];
  int c[100][200];
  int c_tmp[100][200];
  int i = 0, j = 0;
  int N;

  while (1) {
    scanf("%d", &n[i]);
    scanf("%d", &r[i]);
    if (n[i] == r[i] && n[i] == 0) {
      break;
    }
    for (j = 0; j < r[i]; j++) {
      scanf("%d", &p[i][j]);
      scanf("%d", &c[i][j]);
    }
    i++;
  }
  N = i;

  for (i = 0; i < N; i++) {
    for (j = 0; j < 200; j++) {
      data[j] = j + 1;
    }
    for (j = 0; j < r[i]; j++) {
      // print(data, n[i]);//

      c_copy(c_tmp[i], data, p[i][j], c[i][j], n[i]); //
      // printf("c_copy = ");
      // print(c_tmp[i], n[i]);//

      move(data, p[i][j], c[i][j], n[i]);
      // printf("move\\n");
      // print(data, n[i]);

      tmp_in(c_tmp[i], data, p[i][j], c[i][j], n[i]);
      print(data, n[i]);
      puts("");
    }
    printf("%d\\n", data[n[i] - 1]);
  }

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

#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<string> f;
void init() { f.clear(); }

int input() {
  int w, h;
  cin >> w >> h;
  if (w == 0 && h == 0)
    return false;
  string s;
  for (int i = 0; i < h; i++) {
    cin >> s;
    f.push_back(s);
  }
  return true;
}

int vx[] = {0, 0, 1, -1};
int vy[] = {1, -1, 0, 0};

int rec(int x, int y) {
  if (x < 0 || f.size() <= x)
    return 0;
  if (y < 0 || f[x].size() <= y)
    return 0;
  if (f[x][y] != '.')
    return 0;
  f[x][y] = '#';
  int res = 1;
  for (int i = 0; i < 4; i++) {
    res += rec(x + vx[i], y + vy[i]);
  }
  return res;
}

int solve() {
  int x, y;
  for (int i = 0; i < f.size(); i++) {
    for (int j = 0; j < f[i].size(); j++) {
      if (f[i][j] == '@') {
        x = i;
        y = j;
        f[i][j] = '.';
      }
    }
  }
  return rec(x, y);
}

int main() {
  while (init(), input()) {
    cout << solve() << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<string> f;
void init() { f.clear(); }

int input() {
  int w, h;
  cin >> w >> h;
  if (w == 0 && h == 0)
    return false;
  string s;
  for (int i = 0; i < h; i++) {
    cin >> s;
    f.push_back(s);
  }
  return true;
}

int vx[] = {0, 0, 1, -1};
int vy[] = {1, -1, 0, 0};

int rec(int x, int y) {
  if (f[x][y] != '.')
    return 0;
  f[x][y] = '#';
  int res = 1;
  for (int i = 0; i < 4; i++) {
    res += rec(x + vx[i], y + vy[i]);
  }
  return res;
}

int solve() {
  int x, y;
  for (int i = 0; i < f.size(); i++) {
    for (int j = 0; j < f[i].size(); j++) {
      if (f[i][j] == '@') {
        x = i;
        y = j;
        f[i][j] = '.';
      }
    }
  }
  return rec(x, y);
}

int main() {
  while (init(), input()) {
    cout << solve() << endl;
  }
}
Problem p00711 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define frp(i, n) for ((i) = 0; (i) < (n); i++)
int vx[4] = {0, 1, 0, -1};
int vy[4] = {1, 0, -1, 0};
int H, W;
int check(int n1, int n2, int rednum, vector<int> red1, vector<int> red2) {
  for (int i = 0; i < rednum; i++) {
    if (n1 == red1[i] && n2 == red2[i] || n1 < 0 || n2 < 0 || n1 >= H ||
        n2 >= W) {
      return 0;
    }
  }
  return 1;
}
int main() {
  int i, j, now1, now2;
  while (cin >> W >> H, W + H != 0) {
    int num = 1;
    string str2;
    vector<string> str;
    vector<int> red1;
    vector<int> red2;
    frp(i, H) {
      cin >> str2;
      str.push_back(str2);
    }
    frp(i, H) {
      frp(j, W) {
        if (str[i][j] == '#') {
          red1.push_back(i);
          red2.push_back(j);
        }
      }
    }
    queue<pair<int, int>> qii;
    frp(i, H) {
      frp(j, W) {
        if (str[i][j] == '@') {
          qii.push(make_pair(i, j));
          red1.push_back(i);
          red2.push_back(j);
        }
      }
    }
    while (!qii.empty()) {
      now1 = qii.front().first;
      now2 = qii.front().second;
      qii.pop();
      for (i = 0; i < 4; i++) {
        if (check(now1 + vx[i], now2 + vy[i], red1.size(), red1, red2) == 1) {
          red1.push_back(now1 + vx[i]);
          red2.push_back(now2 + vy[i]);
          qii.push(make_pair(now1 + vx[i], now2 + vy[i]));
          num++;
        }
      }
    }
    cout << num << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define frp(i, n) for ((i) = 0; (i) < (n); i++)
int vx[4] = {0, 1, 0, -1};
int vy[4] = {1, 0, -1, 0};
int H, W;
vector<int> red1;
vector<int> red2;
int check(int n1, int n2) {
  for (int i = 0; i < red1.size(); i++) {
    if (n1 == red1[i] && n2 == red2[i] || n1 < 0 || n2 < 0 || n1 > H || n2 > W)
      return 0;
  }
  return 1;
}
int main() {
  int i, j;
  string str2;
  vector<string> str;
  while (cin >> W >> H, W + H != 0) {
    int num = 1;
    frp(i, H) {
      cin >> str2;
      str.push_back(str2);
    }
    frp(i, H) {
      frp(j, W) {
        if (str[i][j] == '#') {
          red1.push_back(i);
          red2.push_back(j);
        }
      }
    }
    queue<pair<int, int>> qii;
    frp(i, H) {
      frp(j, W) {
        if (str[i][j] == '@')
          qii.push(make_pair(i, j));
      }
    }
    while (!qii.empty()) {
      int now1 = qii.front().first;
      int now2 = qii.front().second;
      qii.pop(); //?????????????´??????´?£?
      for (i = 0; i < 4; i++) {
        if (check(now1 + vx[i], now2 + vy[i]) == 1) {
          red1.push_back(now1);
          red2.push_back(now2);
          qii.push(make_pair(now1 + vx[i], now2 + vy[i]));
          num++;
        }
      }
    }
    cout << num << endl;
  }
  return 0;
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

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

int COUNT = 0;

void dfs(vector<string> map, int state[20][20], int x, int y, int W, int H) {
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, -1, 0, 1};
  if (x < 0 || x > H - 1 || y < 0 || y > W - 1)
    return; //????????????
  if (state[x][y] != 0 || map[x][y] == '#')
    return; //?????§????????£??????????????????????????????
  ++COUNT;
  state[x][y] = 1;
  for (int i = 0; i < 4; ++i)
    dfs(map, state, x + dx[i], y + dy[i], W, H); //??????????????¨??¢?´¢
}

int main() {
  int W, H, x, y;
  vector<string> map;
  string a;
  while (true) {
    COUNT = 0;
    cin >> W >> H;
    if (!W && !H)
      break;
    int state[20][20] = {0};      //?????§????????£???????????????
    for (int i = 0; i < H; ++i) { //???????????\\???
      cin >> a;
      map.push_back(a);
    }
    for (int i = 0; i < H; ++i) { //????????????????????¢?´¢
      if (0 <= map[i].find('@') && map[i].find('@') < W) {
        y = map[i].find('@');
        x = i;
        break;
      }
    }
    dfs(map, state, x, y, W, H);
    cout << COUNT << endl;
    map.clear();
  }
}

Error: 0

Fixed submission:

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

int COUNT = 0;

void dfs(vector<string> map, int state[20][20], int x, int y, int W, int H) {
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, -1, 0, 1};
  if (x < 0 || x == H || y < 0 || y == W)
    return; //????????????
  if (state[x][y] != 0 || map[x][y] == '#')
    return; //?????§????????£??????????????????????????????
  ++COUNT;
  state[x][y] = 1;
  for (int i = 0; i < 4; ++i)
    dfs(map, state, x + dx[i], y + dy[i], W, H); //??????????????¨??¢?´¢
}

int main() {
  int W, H, x, y;
  vector<string> map;
  string a;
  while (true) {
    COUNT = 0;
    cin >> W >> H;
    if (!W && !H)
      break;
    int state[20][20] = {0};      //?????§????????£???????????????
    for (int i = 0; i < H; ++i) { //???????????\\???
      cin >> a;
      map.push_back(a);
    }
    for (int i = 0; i < H; ++i) { //????????????????????¢?´¢
      if (0 < map[i].find('@') && map[i].find('@') < W) {
        y = map[i].find('@');
        x = i;
        break;
      }
    }
    dfs(map, state, x, y, W, H);
    cout << COUNT << endl;
    map.clear();
  }
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

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

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
int W, H;
char board[30][30];

int dfs(int y, int x) {
  board[y][x] = '#';
  int ret = 1;
  for (int i = 0; i < 4; i++) {
    int ny = y + dy[i], nx = x + dx[i];
    if (ny >= 0 && ny < H && nx >= 0 && nx < W && board[ny][nx] == '.') {
      ret += dfs(ny, nx);
    }
  }
  return ret;
}

int main() {
  while (cin >> W >> H, W) {
    for (int i = 0; i < H; i++) {
      cin >> board[i];
    }

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (board[i][j] == '@') {
          cout << dfs(i, j) << endl;
        }
      }
    }
  }

  return 0;
}


Error: -11

Fixed submission:

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

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
int W, H;
char board[30][30];

int dfs(int y, int x) {
  board[y][x] = '#';
  int ret = 1;
  for (int i = 0; i < 4; i++) {
    int ny = y + dy[i], nx = x + dx[i];
    if (ny >= 0 && ny < H && nx >= 0 && nx < W && board[ny][nx] == '.') {
      ret += dfs(y, x);
    }
  }
  return ret;
}

int main() {
  while (cin >> W >> H, W) {
    for (int i = 0; i < H; i++) {
      cin >> board[i];
    }

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (board[i][j] == '@') {
          cout << dfs(i, j) << endl;
        }
      }
    }
  }

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

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

#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define REP(i, N, k) for (int i = k; i < (int)(N); i++)

#define vi vector<int>
#define pb push_back

#define pii pair<int, int>
#define fi first
#define se second
int main() {

  //    ifstream in("b_in.txt");
  //    cin.rdbuf(in.rdbuf());

  int w, h;
  while (cin >> w >> h, w) {
    int sx, sy;
    string s[30];
    rep(i, h) cin >> s[i];
    rep(y, h) rep(x, w) if (s[y][x] == '@') s[y][x] = '.', sx = x, sy = y;

    queue<pii> que;
    que.push(pii(sx, sy));
    bool u[30][30] = {};
    u[sy][sx] = true;
    int cnt = 1;
    while (!que.empty()) {
      int x, y;
      tie(x, y) = que.front();
      que.pop();
      rep(i, 4) {
        const int dx[] = {0, 1, 0, -1, 0};
        int nx = x + dx[i];
        int ny = y + dx[i + 1];
        if (nx < 0 || w <= nx || ny < 0 || h <= ny)
          continue;
        if (s[ny][nx] == '#')
          continue;
        if (u[ny][nx])
          continue;
        u[ny][nx] = true;
        cnt += 1;
        que.push(pii(nx, ny));
      }
    }
    cout << cnt << endl;
  }

  return 0;
}


Error: WA

Fixed submission:

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

#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define REP(i, N, k) for (int i = k; i < (int)(N); i++)

#define vi vector<int>
#define pb push_back

#define pii pair<int, int>
#define fi first
#define se second
int main() {

  ifstream in("b_in.txt");
  cin.rdbuf(in.rdbuf());

  int w, h;
  while (cin >> w >> h, w) {
    int sx, sy;
    string s[30];
    rep(i, h) cin >> s[i];
    rep(y, h) rep(x, w) if (s[y][x] == '@') s[y][x] = '.', sx = x, sy = y;

    queue<pii> que;
    que.push(pii(sx, sy));
    bool u[30][30] = {};
    u[sy][sx] = true;
    int cnt = 1;
    while (!que.empty()) {
      int x, y;
      tie(x, y) = que.front();
      que.pop();
      rep(i, 4) {
        const int dx[] = {0, 1, 0, -1, 0};
        int nx = x + dx[i];
        int ny = y + dx[i + 1];
        if (nx < 0 || w <= nx || ny < 0 || h <= ny)
          continue;
        if (s[ny][nx] == '#')
          continue;
        if (u[ny][nx])
          continue;
        u[ny][nx] = true;
        cnt += 1;
        que.push(pii(nx, ny));
      }
    }
    cout << cnt << endl;
  }

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

#include <iostream>
#include <queue>
#include <utility>
using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
queue<pair<int, int>> M;
int W, H;
int q[20 + 5][20 + 5] = {};
char p[20 + 5][20 + 5];
int counter;
int x, y;

int main() {
  while (cin >> W >> H && W != 0) {
    counter = 0;
    for (int i = 1; i <= 22; i++) {
      for (int j = 1; j <= 22; j++) {
        q[i][j] = 0;
        p[i][j] = ' ';
      }
    }
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        cin >> p[i][j];
        if (p[i][j] == '@') {
          M.push(make_pair(i, j));
          counter = 1;
          q[i][j] = 1;
        }
      }
    }
    while (!M.empty()) {
      x = M.front().first;
      y = M.front().second;
      M.pop();
      for (int k = 0; k <= 3; k++) {
        if (p[x + dx[k]][y + dy[k]] == '.' && q[x + dx[k]][y + dy[k]] == 0) {
          M.push(make_pair(x + dx[k], y + dy[k]));
          q[x + dx[k]][y + dy[k]] = 1;
          counter += 1;
        }
      }
    }
    cout << counter << endl;
  }
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <iostream>
#include <queue>
#include <utility>
using namespace std;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};

int main() {
  int W, H;
  int q[20][20];
  char p[20][20];
  queue<pair<int, int>> M;
  pair<int, int> X;
  while (cin >> W >> H) {
    for (int i = 1; i <= 21; i++) {
      for (int j = 1; j <= 21; j++) {
        q[i][j] = 0;
        p[i][j] = ' ';
      }
    }
    if (W == 0)
      return 0;
    int count = 0;
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        cin >> p[i][j];
        if (p[i][j] == '@') {
          M.push(make_pair(i, j));
          count = 1;
          q[i][j] = 1;
        }
      }
    }
    while (!M.empty()) {
      W = M.front().first;
      H = M.front().second;
      M.pop();
      for (int i = 0; i <= 3; i++) {
        if (p[W + dx[i]][H + dy[i]] == '.' && q[W + dx[i]][H + dy[i]] == 0) {
          M.push(make_pair(W + dx[i], H + dy[i]));
          q[W + dx[i]][H + dy[i]] = 1;
          count += 1;
        }
      }
    }
    cout << count << endl;
  }
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int dfs(int x, int y);
int w, h;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
int sum = 1;
char maps[21][21];

int main() {
  int sx, sy;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> maps[i][j];
        if (maps[i][j] == '@') {
          sy = i;
          sx = j;
        }
      }
    }

    dfs(sx, sy);
    cout << sum << endl;
    sum = 1;
  }
  return (0);
}

int dfs(int x, int y) {
  int nx, ny;
  for (int i = 0; i < 4; i++) {
    nx = x + dx[i];
    ny = y + dy[i];
    maps[y][x] = '#';
    if (0 <= nx && nx < w && 0 <= ny && ny < h && maps[ny][nx] != '#') {
      dfs(nx, ny);
      sum++;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int dfs(int x, int y);
int w, h, i, j;
char maps[21][21];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {-1, 0, 1, 0};
int sum = 0;

int main() {
  int sx, sy;
  while (1) {
    sum = 0;
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0)
      break;
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        scanf("%c", &maps[i][j]);
        if (maps[i][j] == '@') {
          sy = i;
          sx = j;
        }
      }
    }
    dfs(sx, sy);
    printf("%d\\n", sum);
  }
  return (0);
}

int dfs(int x, int y) {
  int nx, ny;
  for (i = 0; i < 4; i++) {
    nx = x + dx[i];
    ny = y + dy[i];
    maps[y][x] = '#';
    if (0 <= nx && nx < w && ny < h && maps[ny][nx] != '#') {
      dfs(nx, ny);
      sum++;
    }
  }
  return 0;
}
Problem p00711 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

string t[21];
int w, h;

void dfs(int x, int y) {
  int dx[4] = {1, -1, 0, 0};
  int dy[4] = {0, 0, 1, -1};

  if (((x < 0 || y < 0) || x >= h || y >= w) || t[x][y] != '.')
    return;
  t[x][y] = '@';
  rep(k, 4) { dfs(x + dx[k], y + dy[k]); }
  return;
}

int main(void) {
  int sx = -1, sy = -1, cnt;

  while (true) {
    scanf("%d %d/n", &w, &h);
    if (!w && !h) {
      break;
    }
    rep(i, h) { cin >> t[i]; }

    rep(i, h) rep(j, w) {

      if (t[i][j] == '@') {
        sx = i;
        sy = j;

        t[i][j] = '.';
      }
    }

    dfs(sx, sy);

    cnt = 0;

    rep(i, h) rep(j, w) if (t[i][j] == '@') cnt++;

    cout << cnt << endl;
    ;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

string t[21];

void dfs(int y, int x) {
  int dx[4] = {1, -1, 0, 0};
  int dy[4] = {0, 0, 1, -1};

  if (t[x][y] != '.')
    return;
  t[x][y] = '@';
  rep(k, 4) { dfs(y + dy[k], x + dx[k]); }
  return;
}

int main(void) {

  int w, h, sx, sy, cnt;
  rep(i, 20) rep(j, 21) { t[i][j] == '#'; }

  while (true) {
    scanf("%d %d", &w, &h);
    if (!w && !h)
      return 0;
    for (int i = 1; i <= h; i++) {
      cin >> t[i];
    }
    rep(i, h) rep(j, w) {

      if (t[i][j] == '@') {
        sx = i;
        sy = j;

        t[i][j] = '.';
      }
    }
    dfs(sy, sx);
    cnt = 0;

    rep(i, h) {
      cout << t[i] << endl;
      rep(j, w) if (t[i][j] == '@') cnt++;
    }

    cout << cnt << endl;
    ;
  }

  return 0;
}
Problem p00711 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
char a[21][21];
int c;
void dfs(int y, int x) {
  c++;
  a[y][x] = 0;
  if (y != 0)
    if (a[y - 1][x] == '.')
      dfs(y - 1, x);
  if (y != 20)
    if (a[y + 1][x] == '.')
      dfs(y + 1, x);
  if (x != 0)
    if (a[y][x - 1] == '.')
      dfs(y, x - 1);
  if (x != 20)
    if (a[y][x + 1] == '.')
      dfs(y, x + 1);
}
int main() {
  int w, h, i, j;
  char b[21];
  while (1) {
    scanf("%d%d", &w, &h);
    if (w == 0 && h == 0)
      break;
    for (i = 0; i < 21; i++) {
      for (j = 0; j < 21; j++) {
        a[i][j] = 0;
      }
    }
    for (i = 0; i < h; i++) {
      scanf("%s", b);
      for (j = 0; b[j] != '\\0'; j++) {
        a[i][j] = b[j];
      }
    }
    c = 0;
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        if (a[i][j] == '@')
          dfs(i, j);
      }
    }
    printf("%d\\n", c);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
char a[21][21];
int c;
void dfs(int y, int x) {
  c++;
  a[y][x] = 0;
  if (y != 0)
    if (a[y - 1][x] == '.')
      dfs(y - 1, x);
  if (y != 20)
    if (a[y + 1][x] == '.')
      dfs(y + 1, x);
  if (x != 0)
    if (a[y][x - 1] == '.')
      dfs(y, x - 1);
  if (x != 20)
    if (a[y][x + 1] == '.')
      dfs(y, x + 1);
}
int main() {
  int w, h, i, j;
  while (1) {
    scanf("%d%d", &w, &h);
    if (w == 0 && h == 0)
      break;
    for (i = 0; i < 21; i++) {
      for (j = 0; j < 21; j++) {
        a[i][j] = 0;
      }
    }
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        scanf("%c", &a[i][j]);
      }
    }
    c = 0;
    for (i = 0; i < h; i++) {
      for (j = 0; j < w; j++) {
        if (a[i][j] == '@')
          dfs(i, j);
      }
    }
    printf("%d\\n", c);
  }
  return 0;
}