Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x, 0, sizeof(x))
typedef long long ll;

using namespace std;

static const ll MOD = 1e9 + 7;
static const ll INF = 1e18;
static const ll MAX_H = 2000;
static const ll MAX_W = 2000;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

ll H, W;
// bool M[MAX_H][MAX_W];
void pvector(vector<int> A) {
  cout << "[vector]";
  for (int i = 0; i < A.size(); i++) {
    cout << A[i] << " ";
  }
  cout << endl;
}

int main() {
  cin >> H >> W;
  vector<string> S(H);
  REP(i, H) { cin >> S[i]; }

  short dpL[MAX_H][MAX_W] = {0}, dpR[MAX_H][MAX_W] = {0},
        dpT[MAX_H][MAX_W] = {0}, dpU[MAX_H][MAX_W] = {0};

  REP(i, H) {
    REP(j, W) {
      if (S[i][j] == '.') {
        if (j != 0)
          dpL[i][j] = dpL[i][j - 1] + 1;
        else
          dpL[i][j] = 1;
      }
      // cout << dpL[i][j];
    }
    // cout << endl;
  }
  REP(i, H) {
    REPR(j, W) {
      if (S[i][j] == '.') {
        // cout << dpR[i][j] << endl;
        if (j != W - 1)
          dpR[i][j] = dpR[i][j + 1] + 1;
        else
          dpR[i][j] = 1;
        // cout << dpR[i][j] << endl;
      }
      // cout << dpR[i][j];
    }
    // cout << endl;
  }

  REP(i, H) {
    REP(j, W) {
      if (S[i][j] == '.') {
        if (i != 0)
          dpT[i][j] = dpT[i - 1][j] + 1;
        else
          dpT[i][j] = 1;
      }
      // cout << dpT[i][j];
    }
    // cout << endl;
  }

  REPR(i, H) {
    REP(j, W) {
      if (S[i][j] == '.') {
        if (i != H)
          dpU[i][j] = dpU[i + 1][j] + 1;
        else
          dpU[i][j] = 1;
      }
      // cout << dpU[i][j];
    }
    // cout << endl;
  }

  ll MAX = 0;
  REP(i, H) {
    REP(j, W) {
      if (MAX < (dpL[i][j] + dpR[i][j] + dpT[i][j] + dpU[i][j] - 3)) {
        // cout << i << j << MAX << endl;
        MAX = dpL[i][j] + dpR[i][j] + dpT[i][j] + dpU[i][j] - 3;
      }
    }
  }

  p(MAX);
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x, 0, sizeof(x))
typedef long long ll;

using namespace std;

static const ll MOD = 1e9 + 7;
static const ll INF = 1e18;
static const ll MAX_H = 2000;
static const ll MAX_W = 2000;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

ll H, W;
// bool M[MAX_H][MAX_W];
void pvector(vector<int> A) {
  cout << "[vector]";
  for (int i = 0; i < A.size(); i++) {
    cout << A[i] << " ";
  }
  cout << endl;
}

int main() {
  cin >> H >> W;
  vector<string> S(H);
  REP(i, H) { cin >> S[i]; }

  short dpL[MAX_H][MAX_W] = {0}, dpR[MAX_H][MAX_W] = {0},
        dpT[MAX_H][MAX_W] = {0}, dpU[MAX_H][MAX_W] = {0};

  REP(i, H) {
    REP(j, W) {
      if (S[i][j] == '.') {
        if (j != 0)
          dpL[i][j] = dpL[i][j - 1] + 1;
        else
          dpL[i][j] = 1;
      }
      // cout << dpL[i][j];
    }
    // cout << endl;
  }
  REP(i, H) {
    REPR(j, W) {
      if (S[i][j] == '.') {
        // cout << dpR[i][j] << endl;
        if (j != W - 1)
          dpR[i][j] = dpR[i][j + 1] + 1;
        else
          dpR[i][j] = 1;
        // cout << dpR[i][j] << endl;
      }
      // cout << dpR[i][j];
    }
    // cout << endl;
  }

  REP(i, H) {
    REP(j, W) {
      if (S[i][j] == '.') {
        if (i != 0)
          dpT[i][j] = dpT[i - 1][j] + 1;
        else
          dpT[i][j] = 1;
      }
      // cout << dpT[i][j];
    }
    // cout << endl;
  }

  REPR(i, H) {
    REP(j, W) {
      if (S[i][j] == '.') {
        if (i != H - 1)
          dpU[i][j] = dpU[i + 1][j] + 1;
        else
          dpU[i][j] = 1;
      }
      // cout << dpU[i][j];
    }
    // cout << endl;
  }

  ll MAX = 0;
  REP(i, H) {
    REP(j, W) {
      if (MAX < (dpL[i][j] + dpR[i][j] + dpT[i][j] + dpU[i][j] - 3)) {
        // cout << i << j << MAX << endl;
        MAX = dpL[i][j] + dpR[i][j] + dpT[i][j] + dpU[i][j] - 3;
      }
    }
  }

  p(MAX);
}