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

#include <iostream>
using namespace std;

int F[1000][1000];

//?????????????????????
void r(int yy, int xx, int z) {
  if (F[yy][xx] != z) {
    return;
  }

  F[yy][xx] = 10;

  r(yy - 1, xx, z);
  r(yy, xx + 1, z);
  r(yy + 1, xx, z);
  r(yy, xx - 1, z);
}

int main() {
  int w, h, xs, ys, xg, yg, n;
  int c, d, x, y;

  while (1) {
    cin >> w >> h;

    //?????????????????????0???????????????
    if (w == 0 && h == 0)
      break;
    //???????????????????????????????????\\?????°????±??????£???????????????
    cin >> xs >> ys >> xg >> yg >> n;

    // n?????°???????????????????????????
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y; //?????????????????¨????????±????????????
      if (d == 0) {
        F[x][y] = c;
        F[x + 1][y] = c;
        F[x + 2][y] = c;
        F[x + 3][y] = c;
        F[x][y + 1] = c;
        F[x + 1][y + 1] = c;
        F[x + 2][y + 1] = c;
        F[x + 3][y + 1] = c;
      }
      if (d == 1) {
        F[x][y] = c;
        F[x][y + 1] = c;
        F[x][y + 2] = c;
        F[x][y + 3] = c;
        F[x + 1][y] = c;
        F[x + 1][y + 1] = c;
        F[x + 1][y + 2] = c;
        F[x + 1][y + 3] = c;
      }
    }

    //??\\????????????????????????

    //??????????????????
    r(xs, ys, F[xs][ys]);
    //??´???????????????
    if (F[xg][yg] == 10) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
    //???????????????????????????
    for (int i = 1; i <= w; i++) {
      for (int g = 1; g <= w; g++) {
        F[i][g] = 6;
      }
    }
    //?????????????????????
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[500][500];

//?????????????????????
void r(int yy, int xx, int z) {
  if (F[yy][xx] != z) {
    return;
  }

  F[yy][xx] = 10;

  r(yy - 1, xx, z);
  r(yy, xx + 1, z);
  r(yy + 1, xx, z);
  r(yy, xx - 1, z);
}

void yoko(int c, int x, int y) {
  F[x][y] = c;
  F[x + 1][y] = c;
  F[x + 2][y] = c;
  F[x = 3][y] = c;
  F[x][y + 1] = c;
  F[x + 2][y + 1] = c;
  F[x + 3][y + 1] = c;
  F[x + 4][y + 1] = c;
  return;
}
void tate(int c, int x, int y) {
  F[x][y] = c;
  F[x][y + 1] = c;
  F[x][y + 2] = c;
  F[x][y + 3] = c;
  F[x + 1][y] = c;
  F[x + 1][y + 1] = c;
  F[x + 1][y + 2] = c;
  F[x + 1][y + 3] = c;
  return;
}

int main() {
  int w, h, xs, ys, xg, yg, n;
  int c, d, x, y;

  while (1) {
    cin >> w >> h;

    //?????????????????????0???????????????
    if (w == 0 && h == 0)
      break;
    //???????????????????????????????????\\?????°????±??????£???????????????
    cin >> xs >> ys >> xg >> yg >> n;

    // n?????°???????????????????????????
    for (int i = 0; i < n; i++) {
      cin >> c, d, x, y; //?????????????????¨????????±????????????
      if (d == 0)
        yoko(c, x, y);
      if (d == 1)
        tate(c, x, y);
    }

    //??\\????????????????????????

    //??????????????????
    r(xs, ys, F[xs][ys]);
    //??´???????????????
    if (F[xg][yg] == 10) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
    //?????????????????????
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define rep(i, j) FOR(i, 0, j)
#define rep2(i, k) for (int i = 1; i <= k; ++i)
#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define INF (1 << 30)

using namespace std;

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

int field[105][105], use[105][105];
int h, w, sx, sy, gx, gy, n;
int scol;

void make_map(int x, int y, int chk, int color) {
  if (chk == 0) {
    for (int i = y; i < y + 2; i++) {
      for (int j = x; j < x + 4; j++)
        field[i][j] = color;
    }
  } else {
    for (int i = y; i < y + 4; i++) {
      for (int j = x; j < x + 2; j++)
        field[i][j] = color;
    }
  }
}

bool dfs(int x, int y) {
  use[y][x] = true;
  if (x == gx && y == gy)
    return true;
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (nx >= 0 && nx < w && ny >= 0 && ny < h &&
        field[ny][nx] == field[sy][sx] && !use[ny][nx])
      dfs(nx, ny);
  }
  return use[gy][gx];
}

int main() {
  while (cin >> w >> h, w) {
    memset(field, 0, sizeof(field));
    memset(use, false, sizeof(use));
    int scol = 0;
    cin >> sx >> sy >> gx >> gy;
    --sx;
    --sy;
    --gx;
    --gy;
    cin >> n;
    while (n--) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      --x;
      --y;
      make_map(x, y, d, c);
    }
    if (dfs(sx, sy))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, j) FOR(i, 0, j)
#define rep2(i, k) for (int i = 1; i <= k; ++i)
#define FOR(i, j, k) for (int i = j; i < k; ++i)
#define INF (1 << 30)

using namespace std;

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

int field[105][105];
int h, w, sx, sy, gx, gy, n;
int col, dire, x, y;
int scol;

bool dfs(int nx, int ny) {
  field[ny][nx] = 0;
  if (nx == gx && ny == gy)
    return true;
  rep(i, 4) {
    int tx = nx + dx[i];
    int ty = ny + dy[i];
    if (tx <= w && tx > 0 && ty <= h && field[ty][tx] == scol)
      dfs(tx, ty);
  }
  return false;
}

int main() {
  while (cin >> w >> h, w || h) {
    memset(field, 0, sizeof(field));
    int scol = 0;
    cin >> sx >> sy >> gx >> gy;
    cin >> n;
    rep(k, n) {
      cin >> col >> dire >> x >> y;
      if (dire) {
        rep(i, 4) rep(j, 2) field[y + i][x + j] = col;
      } else {
        rep(i, 2) rep(j, 4) field[y + i][x + j] = col;
      }
      // rep(j, (dire?4:2)) rep(k, (dire?2:4)) field[x + j][y + k] = col;
    }
    scol = field[sx][sy];
    /*rep(i, h + 1){
            rep(j, w + 1) cout << field[i][j] << " ";
            puts("");
    }*/
    if (dfs(sx, sy) || field[y][x] != 0)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int F[102][102];

bool DFS(int X, int Y, int Xg, int Yg, int c) {
  if (F[Y][X] != c) {
    return false;
  } else if (F[Y][X] == c && X == Xg && Y == Yg) {
    return true;
  }
  F[Y][X] = -1;
  if (DFS(X, Y - 1, Xg, Yg, c)) {
    return true;
  } else if (DFS(X + 1, Y, Xg, Yg, c)) {
    return true;
  } else if (DFS(X, Y + 1, Xg, Yg, c)) {
    return true;
  } else if (DFS(X - 1, Y, Xg, Yg, c)) {
    return true;
  }

  return false;
}

int main() {
  while (true) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }
    int xs, ys, xg, yg;
    cin >> xs >> ys >> xg >> yg;
    int n;
    cin >> n;
    for (int y = 0; y < 102; y++) {
      for (int x = 0; x < 102; x++) {
        F[y][x] = -1;
      }
    }
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int X = x; X < x + 4; X++) {
          for (int Y = y; Y < y + 2; Y++) {
            F[Y][X] = c;
          }
        }
      } else if (d == 1) {
        for (int X = x; X < x + 2; X++) {
          for (int Y = y; Y < y + 4; Y++) {
            F[Y][X] = c;
          }
        }
      }
    }
    if (F[ys][xs] != -1) {
      if (DFS(xs, ys, xg, yg, F[ys][xs])) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[102][102];

bool DFS(int X, int Y, int Xg, int Yg, int c) {
  if (F[Y][X] != c) {
    return false;
  } else if (F[Y][X] == c && X == Xg && Y == Yg) {
    return true;
  }
  F[Y][X] = -1;
  if (DFS(X, Y - 1, Xg, Yg, c)) {
    return true;
  } else if (DFS(X + 1, Y, Xg, Yg, c)) {
    return true;
  } else if (DFS(X, Y + 1, Xg, Yg, c)) {
    return true;
  } else if (DFS(X - 1, Y, Xg, Yg, c)) {
    return true;
  }

  return false;
}

int main() {
  while (true) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }
    int xs, ys, xg, yg;
    cin >> xs >> ys >> xg >> yg;
    int n;
    cin >> n;
    for (int y = 0; y < 102; y++) {
      for (int x = 0; x < 102; x++) {
        F[y][x] = -1;
      }
    }
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int X = x; X < x + 4; X++) {
          for (int Y = y; Y < y + 2; Y++) {
            F[Y][X] = c;
          }
        }
      } else if (d == 1) {
        for (int X = x; X < x + 2; X++) {
          for (int Y = y; Y < y + 4; Y++) {
            F[Y][X] = c;
          }
        }
      }
    }
    if (DFS(xs, ys, xg, yg, F[xs][ys])) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
#define MAX 100
static const int dx[4] = {1, 0, -1, 0};
static const int dy[4] = {0, -1, 0, 1};
int w, h, sx, sy, gx, gy, G[MAX + 2][MAX + 2];
bool dfs(int x, int y, int color) {
  if (color == 0 || G[x][y] != color)
    return false;
  if (x == gx && y == gy)
    return true;
  G[x][y] = 0;
  for (int r = 0; r < 4; r++) {
    if (dfs(x + dx[r], y + dy[r], color))
      return true;
  }
  return false;
}
main() {
  int n, c, d, px, py, ww, hh;
  while (cin >> w >> h && w) {
    cin >> sx >> sy >> gx >> gy >> n;
    for (int y = 0; y < h + 2; y++)
      for (int x = 0; x < w + 2; x++)
        G[x][y] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> c >> d >> px >> py;
      if (d == 0) {
        ww = 4;
        hh = 2;
      } else {
        ww = 2;
        hh = 4;
      }
      for (int y = 0; y <= hh - 1; y++)
        for (int x = 0; x <= ww - 1; x++)
          G[px + x][py + y] = c;
    }
    if (dfs(sx, sy, G[sx][sy]))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
struct cordinate {
  int y;
  int x;
};
cordinate SIZE, Start, Goal;
struct Blocks {
  int color;
  int direction;
  int y;
  int x;
};
Blocks block[100];
int N, board[100][100];
int Color, dp[100][100];
int recursion(int y, int x) {
  int res = 0;
  if (y == Goal.y && x == Goal.x) {
    res = 1;
  } else {
    dp[y][x] = 0;
    if (board[y + 1][x] == Color && dp[y + 1][x] == -1)
      res += recursion(y + 1, x);
    if (board[y - 1][x] == Color && dp[y - 1][x] == -1)
      res += recursion(y - 1, x);
    if (board[y][x + 1] == Color && dp[y][x + 1] == -1)
      res += recursion(y, x + 1);
    if (board[y][x - 1] == Color && dp[y][x - 1] == -1)
      res += recursion(y, x - 1);
  }
  return dp[y][x] = res;
}
int main() {
  while (true) {
    for (int i = 0; i < 100; i++)
      for (int j = 0; j < 100; j++)
        dp[i][j] = -1;
    cin >> SIZE.x >> SIZE.y;
    if (SIZE.x + SIZE.y == 0)
      break;
    cin >> Start.x >> Start.y;
    cin >> Goal.x >> Goal.y;
    cin >> N;
    for (int i = 0; i < N; i++) {
      cin >> block[i].color >> block[i].direction;
      cin >> block[i].x >> block[i].y;
      if (block[i].direction) {
        for (int l = block[i].y; l < block[i].y + 4; l++) {
          for (int j = block[i].x; j < block[i].x + 2; j++) {
            board[l][j] = block[i].color;
          }
        }
      } else {
        for (int l = block[i].y; l < block[i].y + 2; l++) {
          for (int j = block[i].x; j < block[i].x + 4; j++) {
            board[l][j] = block[i].color;
          }
        }
      }
    }
    Color = board[Start.y][Start.x];
    if (recursion(Start.y, Start.x) > 0)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#define MAX 105

int map[MAX][MAX];
int xs, ys, xg, yg;
int n;
int w, h;
int c, d, x, y;
int count = 0;
int color;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void jadge(int x, int y) {
  if (count == 0) {
    if (0 <= x && x <= w && 0 <= y && y <= h && map[x][y] == color) {
      map[x][y] = 9;
      if (x == xg && y == yg) {
        count = 1;
        return;
      }
      for (int i = 0; i < 4; i++) {
        jadge(x + dx[i], y + dy[i]);
      }
    }
  }
}
int main() {
  while (1) {
    count = 0;

    for (int i = 0; i < MAX; i++) {
      for (int j = 0; j < MAX; j++) {
        map[i][j] = 0;
      }
    }

    cin >> h >> w;
    if (w == 0 && h == 0)
      break;

    cin >> ys >> xs;
    cin >> yg >> xg;
    xs--;
    ys--;
    xg--;
    yg--;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> y >> x;

      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
          if (d == 1) {
            map[x - 1 + i][y - 1 + j] = c;
          } else {
            map[x - 1 + j][y - 1 + i] = c;
          }
        }
      }
    }
    /*
    for(int i=0; i < w; i++){
            for(int j=0; j < h; j++){
                    cout << map[i][j];
            }
            cout << endl;
    }
    */
    if (map[xs][ys] != map[xg][yg]) {
      cout << "NG" << endl;
      continue;
    } else if (map[xs][ys] == 0 || map[xg][yg] == 0) {
      cout << "NG" << endl;
      continue;
    }
    color = map[xs][ys];

    jadge(xs, ys);

    if (count == 1)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define MAX 100

int map[MAX][MAX];
int xs, ys, xg, yg;
int n;
int w, h;
int c, d, x, y;
int count = 0;
int color;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void jadge(int x, int y) {
  if (count == 0) {
    if (0 <= x && x < w && 0 <= y && y < h && map[x][y] == color) {
      if (x == xg && y == yg) {
        count = 1;
        return;
      }
      for (int i = 0; i < 4; i++) {
        jadge(x + dx[i], y + dy[i]);
      }
    }
  }
}
int main() {
  while (1) {
    count = 0;

    for (int i = 0; i < MAX; i++) {
      for (int j = 0; j < MAX; j++) {
        map[i][j] = 0;
      }
    }

    cin >> w >> h;
    if (w == 0 && h == 0)
      break;

    cin >> xs >> ys;
    cin >> xg >> yg;
    xs--;
    ys--;
    xg--;
    yg--;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> y >> x;

      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
          if (d == 1) {
            map[x - 1 + i][y - 1 + j] = c;
          } else {
            map[x - 1 + j][y - 1 + i] = c;
          }
        }
      }
    }
    if (map[xs][ys] != map[xg][yg]) {
      cout << "NG" << endl;
      continue;
    } else if (map[xs][ys] == 0 || map[xg][yg] == 0) {
      cout << "NG" << endl;
      continue;
    }
    color = map[xs][ys];

    jadge(xs, ys);

    if (count == 1)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
}
Problem p00207 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int board[101][101], w, h;
bool visited[101][101];
int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

bool search(int x, int y, int tarx, int tary, int c) {
  visited[y][x] = true;
  if (board[y][x] != c)
    return false;
  if (x == tarx && y == tary)
    return true;

  for (int k = 0; k < 4; k++) {
    int xx = x + dx[k], yy = y + dy[k];
    if (xx <= 0 || w < xx || yy <= 0 || h < yy)
      continue;
    if (!visited[yy][xx] && search(xx, yy, tarx, tary, c))
      return true;
  }
  return false;
}

int main() {
  for (; cin >> w >> h, w;) {
    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= w; j++)
        board[i][j] = -1, visited[i][j] = false;
    int xs, ys, xg, yg, n;
    cin >> xs >> ys >> xg >> yg >> n;
    while (n--) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      for (int i = 0; i < (d ? 4 : 2); i++)
        for (int j = 0; j < (d ? 2 : 4); j++)
          board[y + i][x + j] = c;
    }

    if (board[ys][xs] != board[yg][xg])
      cout << "NG" << endl;
    else
      cout << (search(xs, ys, xg, yg, board[ys][xs]) ? "OK" : "NG") << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  static int board[101][101], wf[10300][10300];
  int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

  for (int w, h; cin >> w >> h, w;) {
    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= w; j++)
        board[i][j] = -1;
    int xs, ys, xg, yg, n;
    cin >> xs >> ys >> xg >> yg >> n;
    while (n--) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      for (int i = 0; i < (d ? 4 : 2); i++)
        for (int j = 0; j < (d ? 2 : 4); j++)
          board[y + i][x + j] = c;
    }

    if (board[ys][xs] != board[yg][xg])
      cout << "NG" << endl;
    else {
      int clr = board[ys][xs];
      for (int i = 1; i <= w * h; i++)
        for (int j = 1; j <= w * h; j++)
          wf[i][j] = 1000000;
      for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
          if (board[i][j] == clr) {
            for (int k = 0; k < 4; k++) {
              int xx = j + dx[k], yy = i + dy[k];
              if (0 < xx && xx <= w && 0 < yy && yy <= h &&
                  board[yy][xx] == clr)
                wf[w * i + j][w * yy + xx] = wf[w * yy + xx][w * i + j] = 0;
            }
          }
        }
      }

      for (int k = 1; k <= w * h; k++)
        for (int i = 1; i <= w * h; i++)
          for (int j = 1; j <= w * h; j++)
            wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);

      cout << (wf[w * ys + xs][w * yg + xg] == 0 ? "OK" : "NG") << endl;
    }
  }

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

#include <iostream>
using namespace std;

int C[102][102];

void meiro(int W, int H, int c) {
  if (C[W][H] != c) {
    return;
  }

  C[W][H] = -1;

  meiro(W - 1, H, c);
  meiro(W, H + 1, c);
  meiro(W + 1, H, c);
  meiro(W, H - 1, c);
}

int main() {
  while (1) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }

    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        C[i][j] = 0;
      }
    }

    int xs, ys, xg, yg;
    cin >> xs >> ys >> xg >> yg;

    int n;
    cin >> n;

    int c, d, x, y;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = x; j < x + 4; j++) {
          for (int k = y; k < y + 2; k++) {
            C[j][k] = c;
          }
        }
      } else {
        for (int j = x; j < x + 2; j++) {
          for (int k = y; k < y + 4; k++) {
            C[j][k] = c;
          }
        }
      }
    }
    if (C[xs][ys] == 0) {
      cout << "NG" << endl;
      continue;
    }

    meiro(xs, ys, C[xs][ys]);

    if (C[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int C[102][102];

void meiro(int W, int H, int c) {
  if (C[W][H] != c) {
    return;
  }

  C[W][H] = -1;

  meiro(W - 1, H, c);
  meiro(W, H + 1, c);
  meiro(W + 1, H, c);
  meiro(W, H - 1, c);
}

void print(int w, int h) {
  for (int i = 1; i <= w; i++) {
    for (int j = 1; j <= h; j++) {
      cout << C[i][j] << ' ';
    }
    cout << endl;
  }
}

int main() {
  while (1) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }

    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        C[i][j] = 0;
      }
    }

    int xs, ys, xg, yg;
    cin >> xs >> ys >> xg >> yg;

    int n;
    cin >> n;

    int c, d, x, y;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int j = x; j < x + 4; j++) {
          for (int k = y; k < y + 2; k++) {
            C[j][k] = c;
          }
        }
      } else {
        for (int j = x; j < x + 2; j++) {
          for (int k = y; k < y + 4; k++) {
            C[j][k] = c;
          }
        }
      }
    }
    // print(w,h);
    // cout << endl;
    meiro(xs, ys, C[xs][ys]);
    // print(w,h);

    if (C[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

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

#include <iostream>
using namespace std;
#define MAX 100

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

int w, h, xs, ys, xg, yg, G[MAX + 2][MAX + 2];

bool dfs(int x, int y, int color) {
  if (color == 0 || G[x][y] != color)
    return false;
  if (x == xg && y == yg)
    return true;
  G[x][y] = 0;
  for (int r = 0; r < 4; r++) {
    if (dfs(x + dx[r], y + dy[r], color))
      return true;
  }
  return false;
}

int main(void) {
  int n, c, d, bx, by;
  while (cin >> w >> h, w && h) {
    for (int x = 0; x < w + 2; x++) {
      for (int y = 0; y < h + 2; y++) {
        G[x][y] = 0;
      }
    }
    cin >> xs >> ys >> xg >> yg >> n;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> bx >> by;
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
          if (d == 0)
            G[bx + i][by + j] = c;
          else
            G[bx + j][by + i] = c;
        }
      }
    }
    if (dfs(xs, ys, G[xs][ys]))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int a = 0;
int F[102][102];
void DFS(int Xs, int Ys, int c, int Xg, int Yg) {
  if (F[Xs][Ys] != c) {
    return;
  } else if (Xs == Xg && Ys == Yg) {
    a = 1;
    return;
  }
  F[Xs][Ys] = 0;
  DFS(Xs - 1, Ys, c, Xg, Yg);
  DFS(Xs, Ys - 1, c, Xg, Yg);
  DFS(Xs + 1, Ys, c, Xg, Yg);
  DFS(Xs, Ys + 1, c, Xg, Yg);
}

int main() {
  while (1) {
    int w, h, xs, ys, xg, yg, n, C;
    cin >> w >> h;
    if (w == 0 && h == 0) {
      break;
    }
    cin >> xs >> ys >> xg >> yg >> n;
    int c[n], d[n], x[n], y[n];
    for (int i = 0; i < n; i++) {
      cin >> c[i] >> d[i] >> x[i] >> y[i];
      if (xs == x[i] && ys == y[i]) {
        C = c[i];
      }
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 2; k++) {
          if (d[i] == 0) {
            F[x[i + j]][y[i + k]] = c[i];
          } else {
            F[x[i + k]][y[i + j]] = c[i];
          }
        }
      }
    }
    DFS(xs, ys, C, xg, yg);
    if (a == 1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}