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

#include <cstdio>
#include <iostream>

using namespace std;

int n, s;
int use[11] = {0};
int dp[11][(0 * 1 + 1 * 2 + 3 * 2 + 4 * 3 + 5 * 4 + 6 * 5 + 7 * 6 + 8 * 7 +
            9 * 8 + 10 * 9) *
           2] = {0};
inline void combination(register int d, register int sum) {
  dp[d][sum]++;
  if (d == 11)
    return;
  for (int i = 0; i < 10; i++) {
    if (use[i] == 0) {
      use[i] = 1;
      combination(d + 1, sum + (i * d));
      use[i] = 0;
    }
  }
  return;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  combination(1, 0);
  while (cin >> n >> s) {
    if ((0 * 1 + 1 * 2 + 3 * 2 + 4 * 3 + 5 * 4 + 6 * 5 + 7 * 6 + 8 * 7 + 9 * 8 +
         10 * 9) *
            2 >
        s)
      cout << dp[n + 1][s] << endl;
    else
      cout << "0" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int n, s;
int use[10] = {0};
int dp[11][0 * 1 + 1 * 2 + 3 * 2 + 4 * 3 + 5 * 4 + 6 * 5 + 7 * 6 + 8 * 7 +
           9 * 8 + 10 * 9 + 100] = {0};
inline void combination(register int d, register int sum) {
  register int t = 0;
  dp[d][sum]++;
  if (d == 10)
    return;
  for (int i = 0; i < 10; i++) {
    if (use[i] == 0) {
      use[i] = 1;
      combination(d + 1, sum + (i * d));
      use[i] = 0;
    }
  }
  return;
}

int main() {
  std::ios_base::sync_with_stdio(false);
  combination(1, 0);
  while (cin >> n >> s) {
    if (0 * 1 + 1 * 2 + 3 * 2 + 4 * 3 + 5 * 4 + 6 * 5 + 7 * 6 + 8 * 7 + 9 * 8 +
            10 * 9 + 100 >
        s)
      cout << dp[n + 1][s] << endl;
    else
      cout << "0" << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define rep(i, n) for ((i) = 0; (i) < (int)n; (i)++)
#define foreach(i, c)                                                          \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

int n, s, dp[12][1 << 10 + 1][400];

int rec(int k, int S, int sum) {
  // printf("%d %d %d\\n", k, S, sum);

  int i, res = 0;
  if (sum >= 331 || sum < 0)
    return 0;
  if (dp[k][S][sum] >= 0)
    return dp[k][S][sum];
  if (k == n + 1) {
    if (sum == 0) {
      res = 1;
    }
  } else {
    rep(i, 10) if (!((1 << i) & S)) {
      res += rec(k + 1, S | (1 << i), sum - i * k);
    }
  }
  dp[k][S][sum] = res;
  return res;
}

int main() {
  int i;
  while (EOF != scanf("%d%d", &n, &s)) {
    memset(dp, -1, sizeof dp);
    printf("%d\\n", rec(1, 0, s));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#define rep(i, n) for ((i) = 0; (i) < (int)n; (i)++)
#define foreach(i, c)                                                          \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

int n, s;
int res;

void dfs(int sum, int count, int S) {
  int i;
  if (sum > s)
    return;
  if (count == n) {
    if (sum == s)
      res++;
    return;
  }
  rep(i, 10) {
    if (!((1 << i) & S)) {
      dfs(sum + i * (count + 1), count + 1, S | (1 << i));
    }
  }
}

int main() {
  while (cin >> n >> s) {
    res = 0;
    dfs(0, 0, 0);
    cout << res << endl;
  }
  return 0;
}
Problem p00071 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  cin.ignore();
  for (int k = 0; k < n; ++k) {
    int grid[8][8];
    int x, y;
    for (int i = 0; i < 8; ++i) {
      string str;
      cin >> str;
      for (int j = 0; j < 8; ++j) {
        grid[i][j] = str[j] - '0';
      }
    }
    cin >> x;
    cin >> y;
    cin.ignore();

    int dx[12] = {1, 2, 3, 0, 0, 0, -1, -2, -3, 0, 0, 0};
    int dy[12] = {0, 0, 0, 1, 2, 3, 0, 0, 0, -1, -2, -3};
    vector<pair<int, int>> p;
    p.push_back(make_pair(x - 1, y - 1));
    while (!p.empty()) {
      auto pos = p.back();
      grid[pos.second][pos.first] = 0;
      p.pop_back();
      for (int i = 0; i < 12; ++i) {
        int nx = pos.first + dx[i];
        int ny = pos.second + dy[i];
        if (0 <= nx && nx < 8 && 0 <= ny && ny < 8) {
          if (grid[ny][nx] == 1)
            p.push_back(make_pair(nx, ny));
        }
      }
    }

    printf("Data %d:\\n", k + 1);
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        cout << grid[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  cin.ignore();
  for (int k = 0; k < n; ++k) {
    int grid[8][8];
    int x, y;
    for (int i = 0; i < 8; ++i) {
      string str;
      cin >> str;
      for (int j = 0; j < 8; ++j) {
        grid[i][j] = str[j] - '0';
      }
    }
    cin >> x;
    cin >> y;
    cin.ignore();

    int dx[12] = {1, 2, 3, 0, 0, 0, -1, -2, -3, 0, 0, 0};
    int dy[12] = {0, 0, 0, 1, 2, 3, 0, 0, 0, -1, -2, -3};
    vector<pair<int, int>> p;
    p.push_back(make_pair(x - 1, y - 1));
    while (!p.empty()) {
      auto pos = p.back();
      p.pop_back();
      for (int i = 0; i < 12; ++i) {
        int nx = pos.first + dx[i];
        int ny = pos.second + dy[i];
        if (0 <= nx && nx < 8 && 0 <= ny && ny < 8) {
          if (grid[ny][nx] == 1)
            p.push_back(make_pair(nx, ny));
        }
      }
    }

    printf("Data %d:\\n", k + 1);
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        cout << grid[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00071 (C++) — buggy submission, verdict: Runtime Error

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

bool inside(int y, int x) { return 0 <= y && y < 8 && 0 <= x && x < 8; }

int main() {
  int n;
  cin >> n;

  for (int Case = 1; Case <= n; ++Case) {
    bool b[10][10];
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        scanf("%1d", &b[i][j]);
      }
    }

    queue<pair<int, int>> q;
    int x, y;
    int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};

    cin >> x >> y;
    q.push(make_pair(x - 1, y - 1));

    while (!q.empty()) {
      x = q.front().first;
      y = q.front().second;
      q.pop();

      if (!b[y][x])
        continue;
      b[y][x] = false;

      for (int k = 1; k <= 3; ++k) {
        for (int i = 0; i < 4; ++i) {
          int nx = x + k * dx[i];
          int ny = y + k * dy[i];
          if (inside(ny, nx) && b[ny][nx]) {
            q.push(make_pair(nx, ny));
          }
        }
      }
    }

    cout << "Data " << Case << ":" << endl;
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        cout << b[i][j] << (j + 1 == 8 ? "\\n" : "");
      }
    }
  }
}

Error: 0
0 0 0 1 0 0 1 0
0 0 0 0 0 1 0 0
1 0 0 0 1 0 0 1
0 0 1 0 0 0 1 0
0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0
1 0 1 0 0 0 1 0
0 1 0 1 0 0 1 0
???
0 0 0 1 0 0 1 0
0 0 0 0 0 1 0 0
1 0 0 0 1 0 0 1
0 0 1 0 0 0 1 0
0 1 0 0 0 0 0 0
0 0 0 0 1 0 0 0
1 0 1 0 0 0 1 0
0 1 0 1 0 0 1 0
???


Fixed submission:

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

bool inside(int y, int x) { return 0 <= y && y < 8 && 0 <= x && x < 8; }

int main() {
  int n;
  cin >> n;

  for (int Case = 1; Case <= n; ++Case) {
    bool b[10][10];
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        scanf("%1d", &b[i][j]);
      }
    }

    cout << "Data " << Case << ":" << endl;
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        cerr << b[i][j] << (j + 1 == 8 ? "\\n" : " ");
      }
    }

    queue<pair<int, int>> q;
    int x, y;
    int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};

    cin >> x >> y;
    q.push(make_pair(x - 1, y - 1));

    while (!q.empty()) {
      x = q.front().first;
      y = q.front().second;
      q.pop();

      if (!b[y][x])
        continue;
      b[y][x] = false;

      for (int k = 1; k <= 3; ++k) {
        for (int i = 0; i < 4; ++i) {
          int nx = x + k * dx[i];
          int ny = y + k * dy[i];
          if (inside(ny, nx) && b[ny][nx]) {
            q.push(make_pair(nx, ny));
          }
        }
      }
    }

    cerr << "???" << endl;
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        cout << b[i][j] << (j + 1 == 8 ? "\\n" : "");
      }
    }
  }
}
Problem p00071 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>

int field[10][10];

void explosion(int x, int y);

int main(void) {

  int n;

  int bomb_x, bomb_y;

  char buf[100];

  int i, j, k;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {

    getchar();

    fgets(buf, sizeof(buf), stdin);

    for (j = 0; j < 8; j++) {

      fgets(buf, sizeof(buf), stdin);

      buf[strlen(buf) - 1] = '\\0';

      for (k = 0; k < 8; k++) {

        field[j][k] = buf[k] - '0';
      }
    }

    scanf("%d\\n%d", &bomb_x, &bomb_y);

    // printf("%d %d\\n",bomb_x,bomb_y);
    printf("Data %d:\\n", i + 1);

    explosion(bomb_x - 1, bomb_y - 1);

    for (j = 0; j < 8; j++) {

      for (k = 0; k < 8; k++)
        printf("%d", field[j][k]);

      puts("");
    }
  }

  return 0;
}

void explosion(int x, int y) {

  int i;

  field[y][x] = 0;

  for (i = -3; i <= 3; i++) {

    if (y + i < 0 || y + i >= 8)
      continue;

    else if (field[y + i][x] == 1) {

      explosion(x, y + i);
    }
  }

  for (i = -3; i <= 3; i++) {

    if (x + i < 0 || x + i >= 8)
      continue;

    if (field[y][x + i] == 1) {

      explosion(x + i, y);
    }
  }

  return;
}

Error: -11

Fixed submission:

#include <stdio.h>
#include <string.h>

int field[10][10];

void explosion(int x, int y);

int main(void) {

  int n;

  int bomb_x, bomb_y;

  char buf[100];

  int i, j, k;

  scanf("%d", &n);

  getchar();

  for (i = 0; i < n; i++) {

    fgets(buf, sizeof(buf), stdin);

    for (j = 0; j < 8; j++) {

      fgets(buf, sizeof(buf), stdin);

      buf[strlen(buf) - 1] = '\\0';

      for (k = 0; k < 8; k++) {

        field[j][k] = buf[k] - '0';
      }
    }

    scanf("%d\\n%d", &bomb_x, &bomb_y);

    // printf("%d %d\\n",bomb_x,bomb_y);
    printf("Data %d:\\n", i + 1);

    explosion(bomb_x - 1, bomb_y - 1);

    for (j = 0; j < 8; j++) {

      for (k = 0; k < 8; k++)
        printf("%d", field[j][k]);

      puts("");
    }
  }

  return 0;
}

void explosion(int x, int y) {

  int i;

  field[y][x] = 0;

  for (i = -3; i <= 3; i++) {

    if (y + i < 0 || y + i >= 8)
      continue;

    else if (field[y + i][x] == 1) {

      explosion(x, y + i);
    }
  }

  for (i = -3; i <= 3; i++) {

    if (x + i < 0 || x + i >= 8)
      continue;

    if (field[y][x + i] == 1) {

      explosion(x + i, y);
    }
  }

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

#include <cstdio>
#include <iostream>
using namespace std;

void dfs(int x, int y);
int dx[12] = {0, 0, 0, 0, 0, 0, 1, 2, 3, -1, -2, -3};
int dy[12] = {1, 2, 3, -1, -2, -3, 0, 0, 0, 0, 0, 0};
char maps[8][8];

int main() {
  int n, sx, sy;
  cin >> n;
  for (int cas = 1; cas <= n; cas++) {
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        cin >> maps[i][j];
      }
    }
    cin >> sx >> sy;
    dfs(sx - 1, sy - 1);
    cout << "Data " << cas << ":" << endl;
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        cout << maps[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

void dfs(int x, int y) {
  int nx, ny;
  for (int i = 0; i < 12; i++) {
    nx = x + dx[i];
    ny = y + dy[i];
    maps[y][x] = '0';
    if (0 <= nx && nx < 8 && 0 <= ny && ny < 8 && maps[ny][nx] == '1') {
      dfs(nx, ny);
    }
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int dfs(int x, int y);

char maps[8][8];
int dx[12] = {-1, -2, -3, 1, 2, 3, 0, 0, 0, 0, 0, 0};
int dy[12] = {0, 0, 0, 0, 0, 0, -1, -2, -3, 1, 2, 3};
int strx[65] = {0};
int stry[65] = {0};
int k = 0;

int main() {
  int n, sx, sy, cas;
  cin >> n;
  for (cas = 1; cas <= n; cas++) {
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        cin >> maps[i][j];
      }
    }
    cin >> sx >> sy;
    dfs(sx - 1, sy - 1);

    printf("Data %d:\\n", cas);
    dfs(-1, -1);
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        cout << maps[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

int dfs(int x, int y) {
  if (x == -1 && y == -1)
    return 0;
  int nx, ny;
  for (int i = 0; i < 12; i++) {
    nx = x + dx[i];
    ny = y + dy[i];
    maps[y][x] = '0';
    if (0 <= nx && nx < 8 && 0 <= ny && ny < 8 && maps[ny][nx] == '1') {
      strx[k] = nx;
      stry[k] = ny;
      k++;
    }
  }
  if (k == 0)
    return 0;
  k--;
  dfs(strx[k], stry[k]);
}
Problem p00071 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <vector>

using std::vector;

typedef struct bomb {
  int x;
  int y;
} bomb;

int main() {
  const int N = 8;
  int num;
  int mass[N][N];
  vector<bomb> bv;
  char s[9];

  scanf("%d", &num);
  for (int n = 0; n < num; n++) {
    for (int i = 0; i < N; i++) {
      scanf("%s", s);
      for (int j = 0; j < 8; j++) {
        mass[i][j] = s[j] - '0';
      }
    }
    bomb first;
    scanf("%d", &first.x);
    scanf("%d", &first.y);
    first.x--;
    first.y--;
    bv.push_back(first);
    while (!bv.empty()) {
      int x = bv.front().x, y = bv.front().y;
      mass[y][x] = 0;
      for (int dx = -3; dx <= 3; dx++) {
        if (x + dx < 0 || x + dx >= N) {
          continue;
        }
        if (mass[y][x + dx] == 1) {
          bomb b;
          b.x = x + dx;
          b.y = y;
          bv.push_back(b);
        }
      }
      for (int dy = -3; dy <= 3; dy++) {
        if (y + dy < 0 || y + dy >= N) {
          continue;
        }
        if (mass[y + dy][x] == 1) {
          bomb b;
          b.x = x;
          b.y = y + dy;
          bv.push_back(b);
        }
      }
      bv.erase(bv.begin());
    }

    printf("Data %d:\\n", n + 1);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        printf("%d", mass[i][j]);
      }
      printf("\\n");
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>

typedef struct bomb {
  int x;
  int y;
} bomb;

int main() {
  const int N = 10;
  int mass[N][N];
  bomb b[64];
  int cnt = 0, top = 0, end = 0;
  char s[9];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      mass[i][j] = -1;
    }
  }

  int num;
  scanf("%d", &num);
  for (int n = 0; n < num; n++) {
    for (int i = 0; i < 8; i++) {
      scanf("%s", s);
      for (int j = 0; j < 8; j++) {
        mass[i + 1][j + 1] = s[j] - '0';
      }
    }
    scanf("%d", &b[end].x);
    scanf("%d", &b[end].y);
    cnt++;
    end++;
    while (cnt) {
      int x = b[top].x, y = b[top].y;
      mass[y][x] = 0;
      for (int dx = -3; dx <= 3; dx++) {
        if (mass[x + dx][y] == -1) {
          continue;
        }
        if (mass[y][x + dx] == 1) {
          b[end].x = x + dx;
          b[end].y = y;
          cnt++;
          end++;
        }
      }
      for (int dy = -3; dy <= 3; dy++) {
        if (mass[y + dy][x] == -1) {
          continue;
        }
        if (mass[y + dy][x] == 1) {
          b[end].x = x;
          b[end].y = y + dy;
          cnt++;
          end++;
        }
      }
      cnt--;
      top++;
    }

    printf("Data %d:\\n", n + 1);
    for (int i = 0; i < 8; i++) {
      for (int j = 0; j < 8; j++) {
        printf("%d", mass[i + 1][j + 1]);
      }
      printf("\\n");
    }
  }

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define ld long double
#define forever while (true)
int vx[13] = {-3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
int vy[13] = {0, 0, 0, 0, -3, -2, -1, 1, 2, 3, 0, 0, 0};
char a[8][8];
int blow(int x, int y) {
  a[x][y] = '0';
  rep(i, 13) {
    int nextx = x + vx[i];
    int nexty = y + vy[i];
    if (nextx < 0 || 8 <= nextx || nexty < 0 || 8 <= nexty) {
      continue;
    }
    if (a[nextx][nexty] == '1') {
      int u = blow(nextx, nexty);
    }
    a[nextx][nexty] = '0';
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  rep(i, n) {
    // string muda;
    // cin >> muda;

    rep(i1, 8) {
      rep(i2, 8) { cin >> a[i2][i1]; }
    }
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << "Data " << i + 1 << ":" << endl;
    int u = blow(x, y);
    for (int k = 0; k < 8; k++) {
      for (int j = 0; j < 8; j++) {
        cout << a[j][k];
      }
      cout << endl;
    }
  }
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define ld long double
#define forever while (true)
int vx[13] = {-3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
int vy[13] = {0, 0, 0, 0, -3, -2, -1, 1, 2, 3, 0, 0, 0};
int a[8][8];
int blow(int x, int y) {
  a[x][y] = 0;
  rep(i, 13) {
    int nextx = x + vx[i];
    int nexty = y + vy[i];
    if (nextx < 0 || 8 <= nextx || nexty < 0 || 8 <= nexty) {
      continue;
    }
    if (a[nextx][nexty] == 1) {
      int u = blow(nextx, nexty);
    }
    a[nextx][nexty] = 0;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  rep(i, n) {
    rep(i1, 8) {
      rep(i2, 8) { cin >> a[i1][i2]; }
    }
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    int u = blow(x, y);
    for (int k = 0; k < 8; k++) {
      for (int j = 0; j < 8; j++) {
        cout << a[k][j];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00071 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;

typedef pair<int, int> P;

int main() {
  int n, x, y;
  char mp[9][9];
  int dx[4] = {-1, 1, 0, 0};
  int dy[4] = {0, 0, -1, 1};

  cin >> n;

  for (int i = 0; i < n; i++) {

    queue<P> que;

    for (int j = 0; j < 8; j++) {
      cin >> mp[j];
    }
    // cin >> x >> y;
    scanf("%d %d", &x, &y);
    // for(int j = 0;j < 8;j++)

    que.push(P(x - 1, y - 1));
    while (!que.empty()) {
      P now = que.front();
      que.pop();
      mp[now.second][now.first] = '0';
      for (int j = 0; j < 4; j++) {
        for (int k = 1; k <= 3; k++) {
          int ny = now.second + dy[j] * k;
          int nx = now.first + dx[j] * k;
          if (0 <= nx && nx < 8 && 0 <= ny && ny < 8) {
            if (mp[ny][nx] == '1') {
              que.push(P(nx, ny));
              // mp[ny][nx] = '0';
            }
          }
        }
      }
    }
    cout << "Data " << i + 1 << ":" << endl;
    for (int j = 0; j < 8; j++) {
      cout << mp[j] << endl;
    }
  }
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;

typedef pair<int, int> P;

int main() {
  int n, x, y;
  char mp[9][9];
  int dx[4] = {-1, 1, 0, 0};
  int dy[4] = {0, 0, -1, 1};

  cin >> n;

  for (int i = 0; i < n; i++) {

    queue<P> que;

    for (int j = 0; j < 8; j++) {
      cin >> mp[j];
    }
    // cin >> x >> y;
    scanf("%d %d", &x, &y);
    // for(int j = 0;j < 8;j++)

    que.push(P(x - 1, y - 1));
    while (!que.empty()) {
      P now = que.front();
      que.pop();
      // mp[now.second][now.first] = '0';
      for (int j = 0; j < 4; j++) {
        for (int k = 1; k <= 3; k++) {
          int ny = now.second + dy[j] * k;
          int nx = now.first + dx[j] * k;
          if (0 <= nx && nx < 8 && 0 <= ny && ny < 8) {
            if (mp[ny][nx] == '1') {
              que.push(P(nx, ny));
              mp[nx][ny] = '0';
            }
          }
        }
      }
    }
    for (int j = 0; j < 8; j++) {
      cout << mp[j] << endl;
    }
  }
}
Problem p00071 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
/* 入力開始！ */
/* 入力終了！ */
void bakuhatu(char chart[][10][12], int m1, int y, int x) {
  int i, j, k, l;
  int start, end;
  int range = 3;

  chart[m1][y][x] = '0';

  if (x - range < 1)
    start = 0;
  else
    start = x - range;

  if (x + range > 6)
    end = 7;
  else
    end = x + range;

  for (i = start; i <= end; i++) {
    if (chart[m1][y][i] == '1')
      bakuhatu(chart, m1, y, i);
  }

  if (y - range < 1)
    start = 0;
  else
    start = y - range;

  if (y + range > 6)
    end = 7;
  else
    end = y + range;

  for (i = start; i <= end; i++) {
    if (chart[m1][i][x] == '1')
      bakuhatu(chart, m1, i, x);
  }
}
int main(void) {
  int i, j, k, l;
  int a, b, c, d;
  int memory[2];
  int x, y;
  int n;
  char chart[1000][10][12] = {0};
  char iranai[3];

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < 8; j++)
      scanf("%s", chart[i][j]);
    scanf("%d", &x);
    scanf("%d", &y);
    bakuhatu(chart, i, y - 1, x - 1);
  }
  for (i = 0; i < n; i++) {
    printf("Data %d:\\n", i + 1);
    for (j = 0; j < 8; j++)
      printf("%s\\n", chart[i][j]);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void bakuhatu(char chart[][10][12], int m1, int x, int y) {
  int i, j, k, l;
  int start, end;
  int range = 3;

  chart[m1][x][y] = 0;

  if (x - range < 1)
    start = 0;
  else
    start = x - range;

  if (x + range > 7)
    end = 8;
  else
    end = x + range;

  for (i = start; i < end; i++) {
    if (chart[m1][i][y])
      bakuhatu(chart, m1, i, y);
  }

  if (y - range < 1)
    start = 0;
  else
    start = y - range;

  if (y + range > 7)
    end = 8;
  else
    end = y + range;

  for (i = start; i < end; i++) {
    if (chart[m1][x][i])
      bakuhatu(chart, m1, i, y);
  }
}
int main(void) {
  int i, j, k, l;
  int a, b, c, d;
  int memory[2];
  int x, y;
  int n;
  char chart[1000][10][12] = {};
  char iranai[3];

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; j < 10; j++)
      scanf("%s", chart[i][j]);
    scanf("%d", &x);
    scanf("%d", &y);
    bakuhatu(chart, i, x - 1, y - 1);
  }
  for (i = 0; i < n; i++) {
    printf("Data %d:\\n", i + 1);
    for (j = 0; j < 8; j++)
      printf("%s\\n", chart[i][j]);
  }
  return 0;
}