Problem p00092 (C++) — buggy submission, verdict: Runtime Error

#include <cctype>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, l, n) for (int(i) = (int)(l); (i) < (int)(n); (i)++)
#define d_arr(arr, h, w)                                                       \\
  rep(i, (h)) {                                                                \\
    cout << "[";                                                               \\
    rep(j, (w)) { cout << (arr)[i][j] << ", "; }                               \\
    cout << "]" << endl;                                                       \\
  }
#define IN(x, s, g) ((x) >= (s) && (x) < (g))
#define ISIN(x, y, w, h) (IN((x), 0, (w)) && IN((y), 0, (h)))
#define print(x) printf("%d\\n", x);

typedef pair<int, int> P;

class car {
  int id;
  int num;

public:
  car(int x, int y) {
    id = x;
    num = y;
  }
};

int main() {
  char grid[1000][1000];
  int dp[1000][1000];
  int N;
  int maxn = 0;
  cin >> N;
  while (N != 0) {
    maxn = 0;
    rep(i, N) {
      rep(j, N) { cin >> grid[i][j]; }
    }

    rep(i, N) {
      rep(j, N) {
        if (grid[i][j] == '*') {
          dp[i][j] = 0;
          continue;
        }
        if (i == 0 && j == 0) {
          dp[i][j] = 1;
        } else if (i == 0 | j == 0) {
          dp[i][j] = 1;
        } else {
          dp[i][j] = 1 + min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]);
          // cout << "min(" << dp[i-1][j] << "," << dp[i][j-1] << "," <<
          // dp[i-1][j-1] << ") = " << endl; cout << dp[i][j] << endl;
        }
      }
    }

    rep(i, N) {
      rep(j, N) {
        if (maxn < dp[i][j]) {
          maxn = dp[i][j];
        }
      }
    }
    cout << maxn << endl;

    cin >> N;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cctype>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, l, n) for (int(i) = (int)(l); (i) < (int)(n); (i)++)
#define d_arr(arr, h, w)                                                       \\
  rep(i, (h)) {                                                                \\
    cout << "[";                                                               \\
    rep(j, (w)) { cout << (arr)[i][j] << ", "; }                               \\
    cout << "]" << endl;                                                       \\
  }
#define IN(x, s, g) ((x) >= (s) && (x) < (g))
#define ISIN(x, y, w, h) (IN((x), 0, (w)) && IN((y), 0, (h)))
#define print(x) printf("%d\\n", x);

typedef pair<int, int> P;

class car {
  int id;
  int num;

public:
  car(int x, int y) {
    id = x;
    num = y;
  }
};

int main() {
  char grid[500][500];
  int dp[500][500];
  int N;
  int maxn = 0;
  cin >> N;
  while (N != 0) {
    maxn = 0;
    rep(i, N) {
      rep(j, N) { cin >> grid[i][j]; }
    }

    rep(i, N) {
      rep(j, N) {
        if (grid[i][j] == '*') {
          dp[i][j] = 0;
          continue;
        }
        if (i == 0 && j == 0) {
          dp[i][j] = 1;
        } else if (i == 0 | j == 0) {
          dp[i][j] = 1;
        } else {
          dp[i][j] = 1 + min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]);
          // cout << "min(" << dp[i-1][j] << "," << dp[i][j-1] << "," <<
          // dp[i-1][j-1] << ") = " << endl; cout << dp[i][j] << endl;
        }
      }
    }

    rep(i, N) {
      rep(j, N) {
        if (maxn < dp[i][j]) {
          maxn = dp[i][j];
        }
      }
    }
    cout << maxn << endl;

    cin >> N;
  }
  return 0;
}