Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define SORT(v) sort(all(v))
#define SORTD(v) sort(all(v), greater<int>())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 30
#define v(T) vector<T>
#define vv(T) v(v(T))
#define print(x) cout << x << endl
#define printv(v)                                                              \
  for (auto i : v) {                                                           \
    cout << i << " ";                                                          \
  }                                                                            \
  cout << endl
#define printu(v)                                                              \
  for (auto i : v) {                                                           \
    print(i);                                                                  \
  }
#define readv(v, n)                                                            \
  for (int i = 0; i < n; i++)                                                  \
  cin >> v[i]
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int h, w;
v(string) s;

vv(int) vw;
vv(int) vh;
int ret;
int wdfs(int h_index, int w_index) {
  if (w_index >= w)
    return ret;
  if (s[h_index][w_index] == '#') {
    return ret;
  }
  ret++;
  vw[h_index][w_index] = wdfs(h_index, w_index + 1);
  return ret;
}

int hdfs(int h_index, int w_index) {
  if (h_index >= h)
    return ret;
  if (s[h_index][w_index] == '#') {
    return ret;
  }
  ret++;
  vh[h_index][w_index] = hdfs(h_index + 1, w_index);
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  vh = vv(int)(10, vi(10, 0));
  vw = vv(int)(10, vi(10, 0));
  rep(i, h) {
    string k;
    cin >> k;
    s.push_back(k);
  }
  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == '.' && vw[i][j] == 0) {
        vw[i][j] = 1;
        ret = 0;
        wdfs(i, j);
      }
      if (s[i][j] == '.' && vh[i][j] == 0) {
        vh[i][j] = 1;
        ret = 0;
        hdfs(i, j);
      }
    }
  }
  int mx = 0;
  rep(i, h) {
    rep(j, w) { chmax(mx, vw[i][j] + vh[i][j] - 1); }
  }
  print(mx);
  return 0;
}

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

#define endl '\n'
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define SORT(v) sort(all(v))
#define SORTD(v) sort(all(v), greater<int>())
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 30
#define v(T) vector<T>
#define vv(T) v(v(T))
#define print(x) cout << x << endl
#define printv(v)                                                              \
  for (auto i : v) {                                                           \
    cout << i << " ";                                                          \
  }                                                                            \
  cout << endl
#define printu(v)                                                              \
  for (auto i : v) {                                                           \
    print(i);                                                                  \
  }
#define readv(v, n)                                                            \
  for (int i = 0; i < n; i++)                                                  \
  cin >> v[i]
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int h, w;
v(string) s;

vv(int) vw;
vv(int) vh;
int ret;
int wdfs(int h_index, int w_index) {
  if (w_index >= w)
    return ret;
  if (s[h_index][w_index] == '#') {
    return ret;
  }
  ret++;
  vw[h_index][w_index] = wdfs(h_index, w_index + 1);
  return ret;
}

int hdfs(int h_index, int w_index) {
  if (h_index >= h)
    return ret;
  if (s[h_index][w_index] == '#') {
    return ret;
  }
  ret++;
  vh[h_index][w_index] = hdfs(h_index + 1, w_index);
  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  vh = vv(int)(2001, vi(2001, 0));
  vw = vv(int)(2001, vi(2001, 0));
  rep(i, h) {
    string k;
    cin >> k;
    s.push_back(k);
  }
  rep(i, h) {
    rep(j, w) {
      if (s[i][j] == '.' && vw[i][j] == 0) {
        vw[i][j] = 1;
        ret = 0;
        wdfs(i, j);
      }
      if (s[i][j] == '.' && vh[i][j] == 0) {
        vh[i][j] = 1;
        ret = 0;
        hdfs(i, j);
      }
    }
  }
  int mx = 0;
  rep(i, h) {
    rep(j, w) { chmax(mx, vw[i][j] + vh[i][j] - 1); }
  }
  print(mx);
  return 0;
}