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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = j; i < k; i++)
int w, h, xs, ys, xg, yg, n;
int m[102][102];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool DFS(int x, int y, int c) {
  if (m[x][y] != c)
    return false;
  if (x == xg && y == yg)
    return true;
  m[x][y] = -1;
  bool ans = false;
  rep(i, 0, 4) { ans = max(ans, DFS(x + dx[i], y + dy[i], c)); }
  return ans;
}
int main() {
  cin >> w >> h;
  while (w != 0) {
    cin >> xs >> ys >> xg >> yg >> n;
    xs++;
    ys++;
    xg++;
    yg++;
    rep(i, 0, 102) rep(j, 0, 102) m[i][j] = -1;
    rep(i, 0, n) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      x++;
      y++;
      if (d == 0) {
        rep(j, x, x + 4) rep(k, y, y + 2) m[j][k] = c;
      } else {
        rep(j, x, x + 2) rep(k, y, y + 4) m[j][k] = c;
      }
    }
    string ans[2] = {"NG", "OK"};
    if (m[xs][ys] == -1)
      cout << "NG" << endl;
    else
      cout << ans[DFS(xs, ys, m[xs][ys])] << endl;
    cin >> w >> h;
  }
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (int i = j; i < k; i++)
int w, h, xs, ys, xg, yg, n;
int m[102][102];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool DFS(int x, int y, int c) {
  if (m[x][y] != c)
    return false;
  if (x == xg && y == yg)
    return true;
  m[x][y] = -1;
  bool ans = false;
  rep(i, 0, 4) { ans = max(ans, DFS(x + dx[i], y + dy[i], c)); }
  return ans;
}
int main() {
  cin >> w >> h;
  while (w != 0) {
    cin >> xs >> ys >> xg >> yg >> n;
    xs++;
    ys++;
    xg++;
    yg++;
    rep(i, 0, 102) rep(j, 0, 102) m[i][j] = -1;
    rep(i, 0, n) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      x++;
      y++;
      if (d == 0) {
        rep(j, x, x + 4) rep(k, y, y + 2) m[j][k] = c;
      } else {
        rep(j, x, x + 2) rep(k, y, y + 4) m[j][k] = c;
      }
    }
    string ans[2] = {"NG", "OK"};
    cout << ans[DFS(xs, ys, m[xs][ys])] << endl;
    cin >> w >> h;
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int xx[4] = {0, 1, 0, -1};
int yy[4] = {1, 0, -1, 0};
int block[101][101];
int already[101][101];
int w, h;
int xs, ys;
int xg, yg;
int n;
int dfs(int nowx, int nowy);

int main() {
  while (1) {
    memset(block, 0, sizeof(block));
    memset(already, 0, sizeof(already));
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    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;
      int high, wide;
      if (d) {
        high = 4;
        wide = 2;
      } else {
        high = 2;
        wide = 4;
      }
      for (int j = 0; j < high; j++) {
        for (int k = 0; k < wide; k++) {
          block[y + j][x + k] = c;
        }
      }
    }
    int ans = dfs(xs, ys);
    if (ans)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
}

int dfs(int nowx, int nowy) {
  int a = 0;
  already[nowy][nowx] = 1;
  if (nowx == xg && nowy == yg)
    return 1;
  for (int i = 0; i < 4; i++) {
    int nextx = nowx + xx[i];
    int nexty = nowy + yy[i];
    if (0 < nextx && 0 < nexty && nextx <= w && nexty <= h &&
        already[nexty][nextx] != 1 && block[nexty][nextx] == block[ys][xs])
      a += dfs(nextx, nexty);
  }
  return a;
}

Error: TLE

Fixed submission:

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

int xx[4] = {0, 1, 0, -1};
int yy[4] = {1, 0, -1, 0};
int block[100][100];
bool put[100][100];
int already[100][100];
int w, h;
int xs, ys;
int xg, yg;
bool dfs(int nex, int ney);

int main() {
  int n;

  while (1) {
    memset(block, 0, sizeof(block));
    memset(already, 0, sizeof(already));
    memset(put, 0, sizeof(put));
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    cin >> xs >> ys;
    xs--;
    ys--;
    cin >> xg >> yg;
    xg--;
    yg--;
    cin >> n;
    for (int i = 0; i < n; i++) {
      int c, d, x, y;
      int wide, high;
      cin >> c >> d >> x >> y;
      x--;
      y--;
      if (d) {
        wide = 2;
        high = 4;
      } else {
        wide = 4;
        high = 2;
      }
      for (int j = 0; j < high; j++) {
        for (int k = 0; k < wide; k++) {
          block[y + j][x + k] = c;
          put[y + j][x + k] = true;
        }
      }
    }
    bool ans = false;
    if (block[ys][xs] == block[yg][xg]) {
      ans = dfs(xs, ys);
      if (ans)
        cout << "OK" << endl;
      else
        cout << "NG" << endl;
    } else
      cout << "NG" << endl;
  }
}

bool dfs(int nex, int ney) {
  already[nex][ney] = 1;
  if (nex == xg && ney == yg)
    return true;
  for (int i = 0; i < 4; i++) {
    int nx = nex + xx[i];
    int ny = ney + yy[i];
    if (0 <= nx && 0 <= ny && ny < h && nx < w && put[ny][nx] &&
        !already[ny][nx] && block[ys][xs] == block[ny][nx])
      return dfs(nx, ny);
  }
  return false;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define repeat(n, i) for (int i = 0; i < (n); i++)
int w, h;
int xs, ys;
int xg, yg;
int n;

int st_color;

int board[300][300];

#define VISITED 6

bool get_input() {
  memset(board, 0, sizeof(board));
  cin >> w >> h;
  if (w == 0 && h == 0)
    return false;
  //    board.resize(h);
  //    repeat(h, i) board[i].resize(w);
  cin >> xs >> ys;
  cin >> xg >> yg;
  cin >> n;
  repeat(n, i) {
    int c, d, x, y;
    cin >> c >> d >> x >> y;
    if (d == 1) {
      for (int j = y - 1; j < y - 1 + 4; j++) {
        for (int k = x - 1; k < x - 1 + 2; k++) {
          board[j][k] = c;
        }
      }
    } else {
      for (int j = y - 1; j < y - 1 + 2; j++) {
        for (int k = x - 1; k < x - 1 + 4; k++) {
          board[j][k] = c;
        }
      }
    }
  }
  st_color = board[ys - 1][xs - 1];
  return true;
}

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

bool possible;
void dfs(int x, int y) {
  board[y - 1][x - 1] = VISITED;
  if (x == xg && y == yg) {
    possible = true;
    return;
  }
  repeat(4, i) {
    int nx = x + dx[i], ny = y + dy[i];
    if (1 <= nx && nx <= w && 1 <= ny && ny <= h) {
      if (board[ny - 1][nx - 1] == st_color) {
        dfs(nx, ny);
      }
    }
  }
}

// debug
// void solve() {
//    repeat(h, i) {
//        repeat(w, j) {
//            cout << board[i][j] << ' ';
//        }
//        cout << endl;
//    }
//}

void solve() {
  possible = false;
  dfs(xs, ys);
  if (possible)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

int main() {
  while (get_input()) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

#define repeat(n, i) for (int i = 0; i < (n); i++)
int w, h;
int xs, ys;
int xg, yg;
int n;

int st_color;

int board[100][100];

#define VISITED 6

bool get_input() {
  cin >> w >> h;
  if (w == 0 && h == 0)
    return false;
  //    board.resize(h);
  //    repeat(h, i) board[i].resize(w);
  cin >> xs >> ys;
  cin >> xg >> yg;
  cin >> n;
  repeat(n, i) {
    int c, d, x, y;
    cin >> c >> d >> x >> y;
    if (d == 0) {
      for (int j = y - 1; j < y - 1 + 4; j++) {
        for (int k = x - 1; k < x - 1 + 2; k++) {
          board[j][k] = c;
        }
      }
    } else {
      for (int j = y - 1; j < y - 1 + 2; j++) {
        for (int k = x - 1; k < x - 1 + 4; k++) {
          board[j][k] = c;
        }
      }
    }
  }
  st_color = board[ys - 1][xs - 1];
  return true;
}

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

bool possible;
void dfs(int x, int y) {
  board[y - 1][x - 1] = VISITED;
  if (x == xg && y == yg) {
    possible = true;
    return;
  }
  repeat(4, i) {
    int nx = x + dx[i], ny = y + dy[i];
    if (1 <= nx && nx <= w && 1 <= ny && ny <= h) {
      if (board[ny - 1][nx - 1] != VISITED) {
        dfs(nx, ny);
      }
    }
  }
}

void solve() {
  possible = false;
  dfs(xs, ys);
  if (possible)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
}

int main() {
  while (get_input()) {
    solve();
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

typedef pair<int, int> P;
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int w, h, sx, sy, gx, gy, n;
int board[102][102];

int main() {
  while (cin >> w >> h && w) {
    memset(board, 0, sizeof(board));
    cin >> sx >> sy >> gx >> gy >> n;

    int c, d, x, y;
    rep(k, n) {
      cin >> c >> d >> x >> y;
      if (d == 0)
        rep(i, 2) rep(j, 4) board[i + y][j + x] = c;
      else
        rep(i, 4) rep(j, 2) board[i + y][j + x] = c;
    }

    int e = board[sy][sx];
    queue<P> que;
    que.push(P(sx, sy));
    bool ok = false;
    while (!que.empty()) {
      P p = que.front();
      que.pop();
      x = p.first;
      y = p.second;
      if (x == gx && y == gy) {
        ok = true;
        break;
      }
      if (board[y][x] != e)
        continue;

      board[y][x] = -1;
      for (int k = 0; k < 4; k++) {
        int nx = x + dx[k];
        int ny = y + dy[k];
        if (nx >= 1 && nx <= w && ny >= 0 && ny <= h && board[ny][nx] == e)
          que.push(P(nx, ny));
      }
    }

    cout << ((ok) ? "OK" : "NG") << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

typedef pair<int, int> P;
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int w, h, sx, sy, gx, gy, n;
int board[21][21];

int main() {
  while (cin >> w >> h && w) {
    memset(board, 0, sizeof(board));
    cin >> sx >> sy >> gx >> gy >> n;

    int c, d, x, y;
    rep(k, n) {
      cin >> c >> d >> x >> y;
      if (d == 0)
        rep(i, 2) rep(j, 4) board[i + y][j + x] = c;
      else
        rep(i, 4) rep(j, 2) board[i + y][j + x] = c;
    }

    int e = board[sy][sx];
    queue<P> que;
    que.push(P(sx, sy));
    bool ok = false;
    while (!que.empty()) {
      P p = que.front();
      que.pop();
      x = p.first;
      y = p.second;
      if (x == gx && y == gy) {
        ok = true;
        break;
      }
      if (board[y][x] == -1)
        continue;

      board[y][x] = -1;
      for (int k = 0; k < 4; k++) {
        int nx = x + dx[k];
        int ny = y + dy[k];
        if (nx >= 1 && nx <= w && ny >= 0 && ny <= h && board[ny][nx] == e)
          que.push(P(nx, ny));
      }
    }

    cout << ((ok) ? "OK" : "NG") << endl;
  }
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int map[101][101];
int xg, yg;
int w, h;
int col;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
bool flag;

void dfs(int x, int y) {
  map[y][x] = 0;

  if (x == xg && y == yg) {
    flag = true;
    return;
  }

  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];

    if (nx < 0 || ny < 0 || nx >= w || ny >= h)
      continue;
    else if (map[ny][nx] == col)
      dfs(nx, ny);
  }
}

void setblock(int c, int d, int bx, int by) {
  int wlim = 4, hlim = 2;

  if (d == 1) {
    wlim = 2;
    hlim = 4;
  }

  for (int y = 0; y < hlim; y++)
    for (int x = 0; x < wlim; x++)
      map[by + y][bx + x] = c;
}

int main() {
  while (cin >> w >> h, w || h) {
    int xs, ys;
    int n;

    for (int y = 0; y < h; y++)
      for (int x = 0; x < w; x++)
        map[y][x] = 0;

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

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

      cin >> c >> d >> x >> y;
      x--, y--;
      setblock(c, d, x, y);
    }
    col = map[ys][xs];
    flag = false;
    if (col)
      dfs(xs, ys);

    if (flag)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

typedef vector<vector<int>> Matrix;
int w, h, xs, ys, xg, yg, n, color;
string res = "NG";
void write(Matrix &board, int c, int d, int x, int y) {
  int width, length;
  if (d == 0) {
    width = 4;
    length = 2;
  }
  if (d == 1) {
    width = 2;
    length = 4;
  }
  for (int i = 0; i < width; ++i) {
    for (int j = 0; j < length; ++j)
      board[x + i][y + j] = c;
  }
}
void func(Matrix &board, int nx, int ny) {
  if (board[nx][ny] == 0) {
    res = "NG";
    return;
  }
  if (nx == xg && ny == yg) {
    res = "OK";
    return;
  }
  board[nx][ny] = 0;
  if (0 <= nx - 1 && color == board[nx - 1][ny])
    func(board, nx - 1, ny);
  if (0 <= ny - 1 && color == board[nx][ny - 1])
    func(board, nx, ny - 1);
  if (nx + 1 <= w && color == board[nx + 1][ny])
    func(board, nx + 1, ny);
  if (ny + 1 <= h && color == board[nx][ny + 1])
    func(board, nx, ny + 1);
}

int main(void) {
  int c, d, x, y;
  while (cin >> w >> h, w || h) {
    if (w == 0 && h == 0)
      return 0;
    res = "NG";
    cin >> xs >> ys >> xg >> yg >> n;
    xs--;
    ys--;
    xg--;
    yg--;
    Matrix board(w, vector<int>(h, 0));
    for (int i = 0; i < n; ++i) {
      cin >> c >> d >> x >> y;
      --x;
      --y;
      write(board, c, d, x, y);
    }
    color = board[xs][ys];
    func(board, xs, ys);
    cout << res << endl;
    board.clear();
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int F[102][102];
int color, gx, gy;
bool maze;

void DFS1(int Y, int X) {
  if (F[Y][X] != color)
    return;
  if (Y == gy && X == gx)
    maze = true;

  F[Y][X] = 0;

  DFS1(Y - 1, X);
  DFS1(Y, X - 1);
  DFS1(Y, X + 1);
  DFS1(Y + 1, X);
}

int main() {
  int N, M, sx, sy, n;
  cin >> N >> M;
  while (N != 0 && M != 0) {
    cin >> sx >> sy >> gx >> gy >> n;
    int c, d, nx, ny;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> nx >> ny;
      for (int y = ny; y < ny + 2 * (1 + d); y++) {
        for (int x = nx; x < nx + 2 * (2 - d); x++) {
          F[y][x] = c;
        }
      }
    }

    color = F[sy][sx];
    maze = false;
    if (color != 0) {
      DFS1(sy, sx);
    }
    cout << (maze ? "OK" : "NG") << endl;
    for (int y = 0; y < 102; y++) {
      for (int x = 0; x < 102; x++) {
        F[y][x] = 0;
      }
    }
    cin >> N >> M;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int F[102][102];
int color, gx, gy;
bool maze;

void DFS1(int Y, int X) {
  if (F[Y][X] != color)
    return;
  if (Y == gy && X == gx)
    maze = true;

  F[Y][X] = 0;

  DFS1(Y - 1, X);
  DFS1(Y, X - 1);
  DFS1(Y, X + 1);
  DFS1(Y + 1, X);
}

int main() {
  int N, M, sx, sy, n;
  cin >> N >> M;
  while (N != 0 && M != 0) {
    cin >> sx >> sy >> gx >> gy >> n;
    int c, d, nx, ny;
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> nx >> ny;
      for (int y = ny; y < ny + 2 * (1 + d); y++) {
        for (int x = nx; x < nx + 2 * (2 - d); x++) {
          F[y][x] = c;
        }
      }
    }

    color = F[sy][sx];
    maze = false;
    DFS1(sy, sx);
    cout << (maze ? "OK" : "NG") << endl;
    cin >> N >> M;
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int fie[101][101], ans, gol[101][101], st[101][101], col, muki, bx, by;
int bex[4] = {0, 1, 0, -1}, bey[4] = {1, 0, -1, 0}, cou, a, b;
int sx, sy, gx, gy, n;
int func(int y, int x) {
  if (fie[sy][sx] == -1)
    return 0;
  if (y < 1 || x < 1 || y > b || x > a)
    return 0;
  if (fie[y][x] == ans) {
    fie[y][x] = 0;
    for (int i = 0; i < 4; i++) {
      func(y + bey[i], x + bex[i]);
    }
  }
  return 0;
}
int main() {
  for (;;) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    fill(fie[0], fie[0] + 101 * 101, -1);
    cin >> sx >> sy >> gx >> gy;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> col >> muki >> bx >> by;
      if (muki == 0) {
        for (int i = 0; i <= 1; i++) {
          for (int j = 0; j <= 3; j++) {
            fie[by + i][bx + j] = col;
          }
        }
      }
      if (muki == 1) {
        for (int i = 0; i <= 3; i++) {
          for (int j = 0; j <= 1; j++) {
            fie[by + i][bx + j] = col;
          }
        }
      }
    }
    ans = fie[sy][sx];
    if (fie[sy][sx] != 0) {
      func(sy, sx);
    }
    /*for(int i=1;i<=a;i++){
        for(int j=1;j<=b;j++){
            cout<<fie[i][j];
        }
        cout<<endl;
    }*/
    if (!fie[gy][gx])
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
    cou = 0;
    /*for(int i=1;i<=a;i++){
        for(int j=1;j<=b;j++){
            cout<<fie[i][j];
        }
        cout<<endl;
    }*/
  }
  return 0;
}
/*6 5
1 1
5 5
3
2 0 1 1
2 0 2 3
2 0 2 5
*/

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int fie[101][101], ans, gol[101][101], st[101][101], col, muki, bx, by;
int bex[] = {0, 1, 0, -1}, bey[] = {1, 0, -1, 0}, cou;
int func(int y, int x) {
  if (y < 1 || x < 1)
    return 0;
  if (fie[y][x] == 0)
    return 0;
  if (fie[y][x] == 6) {
    cou = 1;
    return 0;
  }
  if (cou == 1)
    return 0;
  if (fie[y][x] != ans) {
    fie[y][x] = 0;
    return 0;
  }
  if (fie[y][x] == ans) {
    for (int i = 0; i < 4; i++) {
      func(y + bey[i], x + bex[i]);
    }
  }
  return 0;
}
int main() {
  int a, b, sx, sy, gx, gy, n;
  for (;;) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    fill(fie[0], fie[0] + 101 * 101, 0);
    cin >> sx >> sy >> gx >> gy;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> col >> muki >> bx >> by;
      if (muki == 0) {
        for (int i = 0; i <= 1; i++) {
          for (int j = 0; j <= 3; j++) {
            fie[by + i][bx + j] = col;
          }
        }
      }
      if (muki == 1) {
        for (int i = 0; i <= 3; i++) {
          for (int j = 0; j <= 1; j++) {
            fie[by + i][bx + j] = col;
          }
        }
      }
    }
    fie[gy][gx] = 6;
    ans = fie[sy][sx];
    func(sy, sx);
    if (cou == 1)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
    cou = 0;
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#define int long long
using namespace std;
int w, h, sx, sy, gx, gy, n, c, d, x, y, sc;
int fld[101][101];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
void dfs(int fx, int fy) {
  if (fld[fy][fx] != sc || fx < 1 || fy < 1 || fx > w || fy > h)
    return;
  fld[fy][fx] = 0;
  for (int i = 0; i < 4; i++) {
    dfs(fx + dx[i], fy + dy[i]);
  }
}
signed main() {
  for (;;) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    cin >> sx >> sy >> gx >> gy >> n;
    fill(fld[0], fld[0] + 101 * 101, -1);
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int j = 0; j < 2; j++) {
          for (int k = 0; k < 4; k++) {
            fld[y + j][x + k] = c;
          }
        }
      }
      if (d == 1) {
        for (int j = 0; j < 4; j++) {
          for (int k = 0; k < 2; k++) {
            fld[y + j][x + k] = c;
          }
        }
      }
    }
    sc = fld[sy][sx];
    dfs(sx, sy);
    if (fld[gy][gx] == 0)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#define int long long
using namespace std;
int w, h, xs, ys, xg, yg, n, c, d, x, y, nok, sc;
int fld[101][101];
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
void dfs(int fx, int fy) {
  if (fld[fy][fx] != sc || nok == 1 || fx < 0 || fx > w - 1 || fy < 0 ||
      fy > h - 1)
    return;
  if (fx == xg - 1 && fy == yg - 1) {
    if (sc == fld[fy][fx])
      nok = 1;
  }
  fld[fy][fx] = 0;
  for (int i = 0; i < 4; i++) {
    dfs(fx + dx[i], fy + dy[i]);
  }
}
signed main() {
  for (;;) {
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    cin >> xs >> ys;
    cin >> xg >> yg;
    cin >> n;
    nok = 0;
    fill(fld[0], fld[0] + 101, 0);
    for (int i = 0; i < n; i++) {
      cin >> c >> d >> x >> y;
      x--, y--;
      if (d == 0) {
        for (int j = 0; j < 2; j++) {
          for (int k = 0; k < 4; k++) {
            fld[y + j][x + k] = c;
          }
        }
      }
      if (d == 1) {
        for (int j = 0; j < 4; j++) {
          for (int k = 0; k < 2; k++) {
            fld[y + j][x + k] = c;
          }
        }
      }
    }
    sc = fld[ys][xs];
    dfs(0, 0);
    if (nok == 1)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}
Problem p00207 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int color[200][200];
bool flg[200][200];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int w, h, n, c, d, x, y;

void dfs(int ny, int nx, int gy, int gx) {
  flg[ny][nx] = true;
  rep(i, 4) {
    int nex = nx + dx[i];
    int ney = ny + dy[i];
    if (nex >= w || nex < 0 || ney >= h || ney < 0)
      continue;
    if (color[ney][nex] == color[ny][nx] && flg[ney][nex] == false)
      dfs(ney, nex, gy, gx);
  }
  return;
}

int main() {
  pair<int, int> s, g;
  while (1) {
    rep(i, 200) rep(j, 200) color[i][j] = flg[i][j] = 0;
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    cin >> s.first >> s.second;
    cin >> g.first >> g.second;
    cin >> n;
    rep(i, n) {
      cin >> c >> d >> x >> y;
      if (d == 0) {
        rep(j, 2) {
          rep(k, 4) { color[y - 1 + j][x - 1 + k] = c; }
        }
      } else {
        rep(j, 4) {
          rep(k, 2) { color[y - 1 + j][x - 1 + k] = c; }
        }
      }
    }
    dfs(s.second - 1, s.first - 1, g.second - 1, g.first - 1);
    if (flg[g.second - 1][g.first - 1])
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int color[200][200];
bool flg[200][200];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int ny, int nx, int gy, int gx) {
  flg[ny][nx] = true;
  rep(i, 4) {
    if (color[ny + dy[i]][nx + dx[i]] == color[ny][nx] &&
        flg[ny + dy[i]][nx + dx[i]] == false)
      dfs(ny + dy[i], nx + dx[i], gy, gx);
  }
  return;
}

int main() {
  int w, h, n, c, d, x, y;
  pair<int, int> s, g;
  while (1) {
    rep(i, 200) rep(j, 200) color[i][j] = flg[i][j] = 0;
    cin >> w >> h;
    if (w == 0 && h == 0)
      break;
    cin >> s.first >> s.second;
    cin >> g.first >> g.second;
    cin >> n;
    rep(i, n) {
      cin >> c >> d >> x >> y;
      if (d == 0) {
        rep(j, 2) {
          rep(k, 4) { color[y - 1 + j][x - 1 + k] = c; }
        }
      } else {
        rep(j, 4) {
          rep(k, 2) { color[y - 1 + j][x - 1 + k] = c; }
        }
      }
    }
    dfs(s.first - 1, s.second - 1, g.first - 1, g.second - 1);
    if (flg[g.second - 1][g.first - 1])
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}