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

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -2000;
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y + 1, X, c);
  DFS(Y, X - 1, c);
}

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

    cin >> xs >> ys >> xg >> yg >> n;
    int c[n], d[n], x[n], y[n], ca;
    for (int i = 0; i < n; i++) {
      cin >> c[i] >> d[i] >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++) {
      if (c[i] == 0)
        ca = 10;
      else if (i == n - 1)
        ca = 0;
    }
    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        F[i][j] = 10;
      }
    }
    for (int i = 0; i < n; i++) {
      if (d[i] == 0) {
        for (int j = 0; j < 4; j++) {
          F[x[i] + j][y[i]] = c[i];
          F[x[i] + j][y[i] + 1] = c[i];
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x[i]][y[i] + j] = c[i];
          F[x[i] + 1][y[i] + j] = c[i];
        }
      }
    }

    DFS(xs, ys, F[xs][ys]);

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


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -2000;
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y + 1, X, c);
  DFS(Y, X - 1, c);
}

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

    cin >> xs >> ys >> xg >> yg >> n;
    int c[n], d[n], x[n], y[n], ca;
    for (int i = 0; i < n; i++) {
      cin >> c[i] >> d[i] >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++) {
      if (c[i] == 0)
        ca = 10;
      else if (i == n - 1)
        ca = 0;
    }
    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 102; j++) {
        F[i][j] = ca;
      }
    }
    for (int i = 0; i < n; i++) {
      if (d[i] == 0) {
        for (int j = 0; j < 4; j++) {
          F[x[i] + j][y[i]] = c[i];
          F[x[i] + j][y[i] + 1] = c[i];
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x[i]][y[i] + j] = c[i];
          F[x[i] + 1][y[i] + j] = c[i];
        }
      }
    }

    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -2000) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c || Y > w || X > h) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 105; i++) {
      for (int j = 0; j < 105; j++) {
        F[i][j] = 10;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }

    DFS(xs, ys, F[xs][ys]);

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


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[105][105];
int xg, yg, w, h;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c || Y > w || X > h) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y + 1, X, c);
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y, X - 1, c);
}

int main() {
  int xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 105; i++) {
      for (int j = 0; j < 105; j++) {
        F[i][j] = 0;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }

    DFS(xs, ys, F[xs][ys]);

    if (F[xg][yg] == -1) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}
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 < 20; i++) {
      for (int j = 0; j < 20; 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]);
    // print(w,h);

    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 < 20; i++) {
      for (int j = 0; j < 20; 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;
    if (c == 0) {
      cout << "NG" << endl;
      continue;
    }
    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;

int F[105][105];
int xg, yg;

void DFS(int Y, int X, int c) {
  if (F[Y][X] != c) {
    return;
  }

  F[Y][X] = -1;
  DFS(Y - 1, X, c);
  DFS(Y, X + 1, c);
  DFS(Y + 1, X, c);
  DFS(Y, X - 1, c);
}

int main() {
  int w, h, xs, ys, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    for (int i = 0; i < 20; i++) {
      for (int j = 0; j < 20; j++) {
        F[i][j] = 0;
      }
    }

    cin >> xs >> ys >> xg >> yg >> n;

    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int j = 0; j < 4; j++) {
          F[x + j][y] = c;
          F[x + j][y + 1] = c;
        }
      } else {
        for (int j = 0; j < 4; j++) {
          F[x][y + j] = c;
          F[x + 1][y + j] = c;
        }
      }
    }
    if (F[xs][ys] == 0) {
      cout << "NG" << endl;
      continue;
    }
    DFS(xs, ys, F[xs][ys]);

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


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[102][102];

int DFS(int Y, int X, int c) {
  int cnt = 0;
  if (F[Y][X] != c) {
    return 0;
  }

  F[Y][X] = -1;
  cnt += DFS(Y - 1, X, c);
  cnt += DFS(Y, X + 1, c);
  cnt += DFS(Y + 1, X, c);
  cnt += DFS(Y, X - 1, c);
  return cnt;
}

int main() {
  int w, h, xs, ys, xg, yg, n;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    cin >> xs >> ys >> xg >> yg >> n;

    DFS(xs, ys, F[xs][ys]);
    if (xs == 8) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int field[128][128];
bool memo[128][128];
int w, h;
void func(int x, int y, int c) {
  if (x < 1 || y < 1 || x > w || y > h)
    return;
  if (memo[y][x])
    return;
  if (field[y][x] != c)
    return;
  memo[y][x] = 1;
  func(x - 1, y, c);
  func(x + 1, y, c);
  func(x, y + 1, c);
  func(x, y - 1, c);
  return;
}
int main() {
  while (scanf("%d%d", &w, &h), w, h) {
    int xs, ys, xg, yg, n;
    memset(field, 0, sizeof(field));
    memset(memo, 0, sizeof(memo));
    scanf("%d%d%d%d%d", &xs, &ys, &xg, &yg, &n);
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      scanf("%d%d%d%d", &c, &d, &x, &y);
      if (d == 0) {
        for (int j = x; j < x + 4; j++) {
          field[y][j] = c;
          field[y + 1][j] = c;
        }
      } else {
        for (int j = y; j < y + 4; j++) {
          field[j][x] = c;
          field[j][x + 1] = c;
        }
      }
    }
    func(xs, ys, field[ys][xs]);
    cout << (memo[yg][xg] ? "OK" : "NG") << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int field[128][128];
bool memo[128][128];
int dx[] = {-1, 0, 0, 1}, dy[] = {0, -1, 1, 0};
int w, h;
void func(int x, int y, int c) {
  if (memo[y][x])
    return;
  if (field[y][x] != c)
    return;
  memo[y][x] = 1;
  for (int i = 0; i < 4; i++) {
    func(x + dx[i], y + dy[i], c);
  }
  return;
}
int main() {
  while (scanf("%d%d", &w, &h), w, h) {
    int xs, ys, xg, yg, n;
    memset(field, 0, sizeof(field));
    memset(memo, 0, sizeof(memo));
    scanf("%d%d%d%d%d", &xs, &ys, &xg, &yg, &n);
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      scanf("%d%d%d%d", &c, &d, &x, &y);
      if (d == 0) {
        for (int j = x; j < x + 4; j++) {
          field[y][j] = c;
          field[y + 1][j] = c;
        }
      } else {
        for (int j = y; j < y + 4; j++) {
          field[j][x] = c;
          field[j][x + 1] = c;
        }
      }
    }
    func(xs, ys, field[ys][xs]);
    cout << (memo[yg][xg] == 1 ? "OK" : "NG") << endl;
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

struct Data {
  int y, x;
  Data() {}
  Data(int _y, int _x) {
    y = _y;
    x = _x;
  }
};

int fld[100][100];

void PaintFld(int c, int y, int x, int h, int w) {
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      fld[y + i][x + j] = c;
    }
  }
}

int main() {
  int W, H;
  while (cin >> W >> H, W || H) {
    fill_n((int *)fld, 100 * 100, 0);
    int Xs, Ys, Xg, Yg, N, C, D, X, Y;
    cin >> Xs >> Ys >> Xg >> Yg >> N;
    Xs--;
    Ys--;
    Xg--;
    Yg--;
    for (int i = 0; i < N; i++) {
      cin >> C >> D >> X >> Y;
      X--;
      Y--;
      if (D == 0)
        PaintFld(C, Y, X, 2, 4);
      else
        PaintFld(C, Y, X, 4, 2);
    }

    queue<Data> q;
    Data q_front;
    bool memo[100][100] = {}, ans = false;
    q.push(Data(Ys, Xs));
    while (!q.empty()) {
      q_front = q.front();
      q.pop();

      if (fld[q_front.y][q_front.x] == 0 ||
          fld[q_front.y][q_front.x] != fld[Ys][Xs])
        continue;

      if (q_front.y == Yg && q_front.x == Xg) {
        ans = true;
        break;
      }

      if (memo[q_front.y][q_front.x])
        continue;
      memo[q_front.y][q_front.x] = true;

      for (int i = 0; i < 4; i++) {
        int ny = q_front.y + dy[i];
        int nx = q_front.x + dx[i];
        if (ny < 0 || H <= ny || nx < 0 || W <= nx)
          continue;
        q.push(Data(ny, nx));
      }
    }

    if (ans)
      puts("OK");
    else
      puts("NG");
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int w, h, xs, ys, xg, yg, stage[102][102] = {};
int ny[4] = {0, 1, 0, -1}, nx[4] = {1, 0, -1, 0};
int bc;
bool ans = false;
void func(int x, int y) {
  if (x == xg && y == yg) {
    ans = true;
  }
  for (int i = 0; i < 4; i++) {
    if (stage[y + ny[i]][x + nx[i]] != bc)
      return;
    func(x + nx[i], y + ny[i]);
  }
}
int main() {
  int n, c, d, x, y, bw, bh;
  while (1) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      return 0;
    cin >> xs >> ys >> xg >> yg >> n;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y;
      if (d == 0) {
        bw = 4;
        bh = 2;
      } else {
        bw = 2;
        bh = 4;
      }
      for (int j = 0; j < bh; j++) {
        for (int k = 0; k < bw; k++) {
          stage[y + j][x + k] = c;
        }
      }
    }
    bc = stage[1][1];
    if (bc == 0)
      cout << "NG\\n";
    func(1, 1);
    if (ans == true)
      cout << "OK\\n";
    else
      cout << "NG\\n";
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

char F[102][102];

void Block(int c, int d, int x, int y) {
  if (d == 0) {
    for (int i = 0; i < 4; i++) {
      F[y][x + i] = c;
      F[y + 1][x + i] = c;
    }
  } else {
    for (int i = 0; i < 4; i++) {
      F[y + i][x] = c;
      F[y + i][x + 1] = c;
    }
  }
}
void DFS(int y, int x, int c) {
  if (F[y][x] != c)
    return;

  F[y][x] = 6;

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


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

char F[101][101];

void Block(int c, int d, int x, int y) {
  if (d == 0) {
    for (int i = 0; i < 4; i++) {
      F[y][x + i] = c;
      F[y + 1][x + i] = c;
    }
  } else {
    for (int i = 0; i < 4; i++) {
      F[y + i][x] = c;
      F[y + i][x + 1] = c;
    }
  }
}
void DFS(int y, int x, int c) {
  if (F[y][x] != c)
    return;

  F[y][x] = 6;

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

#include <iostream>
using namespace std;

int a[102][102], color;

void dfs(int x, int y) {

  a[y][x] = 9;

  if (a[y + 1][x] == color) {
    dfs(x, y + 1);
  }
  if (a[y][x + 1] == color) {
    dfs(x + 1, y);
  }
  if (a[y - 1][x] == color) {
    dfs(x, y - 1);
  }
  if (a[y][x - 1] == color) {
    dfs(x - 1, y);
  }
}

int main() {

  int xs, ys, xg, yg, n, c, d, x, y, w, h;

  while (1) {

    cin >> w >> h;

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

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

    cin >> xs >> ys;
    cin >> xg >> yg;

    cin >> n;

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

      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int i = 0; i < 2; i++) {
          for (int j = 0; j < 4; j++) {
            a[i + y][j + x] = c;
          }
        }
      } else {
        for (int i = 0; i < 4; i++) {
          for (int j = 0; j < 2; j++) {
            a[i + y][j + x] = c;
          }
        }
      }
    }

    /*
      for(int i = 0 ; i < h+2 ; i ++){
      for(int j = 0 ; j < w+2 ; j++){
      cout << a[i][j];
      }
      cout <<endl;
      }
      cout <<endl;
    */

    if (a[ys][xs] != 0) {
      color = a[ys][xs];
      dfs(xs, ys);
    }

    /*
      for(int i = 0 ; i < h+2 ; i ++){
      for(int j = 0 ; j < w+2 ; j++){
      cout << a[i][j];
      }
      cout <<endl;
      }
    */

    if (a[yg][xg] == 9) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int a[200][200], color;

void dfs(int x, int y) {

  if (x < 102 && y < 102) {

    a[y][x] = 9;

    if (a[y + 1][x] == color) {
      dfs(x, y + 1);
    }
    if (a[y][x + 1] == color) {
      dfs(x + 1, y);
    }
    if (a[y - 1][x] == color) {
      dfs(x, y - 1);
    }
    if (a[y][x - 1] == color) {
      dfs(x - 1, y);
    }
  }
}

int main() {

  int xs, ys, xg, yg, n, c, d, x, y, w, h;

  while (1) {

    cin >> w >> h;

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

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

    cin >> xs >> ys;
    cin >> xg >> yg;

    cin >> n;

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

      cin >> c >> d >> x >> y;

      if (d == 0) {
        for (int i = 0; i < 2; i++) {
          for (int j = 0; j < 4; j++) {
            a[i + y][j + x] = c;
          }
        }
      } else {
        for (int i = 0; i < 4; i++) {
          for (int j = 0; j < 2; j++) {
            a[i + y][j + x] = c;
          }
        }
      }
    }

    /*
      for(int i = 0 ; i < h+2 ; i ++){
      for(int j = 0 ; j < w+2 ; j++){
      cout << a[i][j];
      }
      cout <<endl;
      }
      cout <<endl;
    */

    color = a[ys][xs];
    dfs(xs, ys);

    /*
      for(int i = 0 ; i < h+2 ; i ++){
      for(int j = 0 ; j < w+2 ; j++){
      cout << a[i][j];
      }
      cout <<endl;
      }
    */

    if (a[yg][xg] == 9) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }

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

#include <iostream>
using namespace std;

int Array[200][200];
#define START 20

void DFS(int h, int w, int c) {

  if (Array[h][w] != c || Array[h][w] == 0 || Array[h][w] == 6) {
    return;
  }

  int tmp = Array[h][w];

  Array[h][w] = 6;

  DFS(h - 1, w, tmp);
  DFS(h, w + 1, tmp);
  DFS(h + 1, w, tmp);
  DFS(h, w - 1, tmp);
}

int main() {

  while (1) {
    int H, W;
    int Start[2], Goal[2];
    int BlockNum;
    int color, dir, xpos, ypos;

    for (int i = 0; i < 200; i++) {
      for (int j = 0; j < 200; j++) {
        Array[i][j] = 0;
      }
    }

    cin >> H >> W;

    if (H == 0 && W == 0) {
      break;
    }

    cin >> Start[0] >> Start[1];

    cin >> Goal[0] >> Goal[1];

    cin >> BlockNum;

    for (int i = 0; i < BlockNum; i++) {
      cin >> color >> dir >> xpos >> ypos;
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
          if (!dir) { //?¨?
            Array[xpos + i][ypos + j] = color;
          } else {
            Array[xpos + j][ypos + i] = color;
          }
        }
      }
    }

    /*for(int i=1;i<=H;i++){
      for(int j=1;j<=W;j++){
        cout << Array[i][j];
      }
      cout << endl;
    }*/
    if (Array[Start[0]][Start[1]] != 0) {
      DFS(Start[0], Start[1], Array[Start[0]][Start[1]]);
    }
    if (Array[Goal[0]][Goal[1]] == 6) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int Array[200][200];
bool is_goal = false;
#define START 20
#define GOAL 30

void DFS(int h, int w, int c) {

  if (Array[h][w] = START) {
    DFS(h - 1, w, Array[h - 1][w]);
    DFS(h, w + 1, Array[h][w + 1]);
    DFS(h + 1, w, Array[h + 1][w]);
    DFS(h, w - 1, Array[h][w - 1]);
  }

  if (!is_goal) {

    if (Array[h][w] == GOAL) {
      is_goal = true;
      return;
    }

    if (Array[h][w] != c || Array[h][w] == '.') {
      return;
    }

    char tmp = Array[h][w];

    Array[h][w] = '.';

    DFS(h - 1, w, tmp);
    DFS(h, w + 1, tmp);
    DFS(h + 1, w, tmp);
    DFS(h, w - 1, tmp);
  }
}

int main() {

  while (1) {
    int H, W;
    int Start[2], Goal[2];
    int BlockNum;
    int color, dir, xpos, ypos;

    cin >> H >> W;

    if (H == 0 && W == 0) {
      break;
    }

    cin >> Start[0] >> Start[1];
    Array[Start[0]][Start[1]] = START;

    cin >> Goal[0] >> Goal[1];
    Array[Goal[0]][Goal[1]] = GOAL;

    cin >> BlockNum;

    for (int i = 0; i < BlockNum; i++) {
      cin >> color >> dir >> xpos >> ypos;
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 2; j++) {
          if (!dir) { //?¨?
            Array[xpos + i][ypos + j] = color;
          } else {
            Array[xpos + j][ypos + i] = color;
          }
        }
      }
    }
    DFS(Start[0], Start[1], Array[Start[0]][Start[1]]);

    if (is_goal) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}