Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, h) cin >> s[i];

  vector<vector<int>> ww(w + 5, vector<int>(w + 5, 0));
  vector<vector<int>> hh(h + 5, vector<int>(h + 5, 0));
  REP(i, h) {
    REP(j, w) {
      if (j == 0)
        ww[i][j] = (s[i][j] == '.' ? 1 : 0);
      else {
        ww[i][j] = (s[i][j] == '.' ? ww[i][j - 1] + 1 : 0);
      }
    }
  }
  REP(i, w) {
    REP(j, h) {
      if (j == 0)
        hh[j][i] = (s[j][i] == '.' ? 1 : 0);
      else {
        hh[j][i] = (s[j][i] == '.' ? hh[j - 1][i] + 1 : 0);
      }
    }
  }

  REP(i, h)
  FOR(j, 1, w) if (ww[i][w - j] != 0 && ww[i][w - j - 1] != 0)
      ww[i][w - j - 1] = ww[i][w - j];
  REP(i, w)
  FOR(j, 1, h) if (hh[h - j][i] != 0 && hh[h - j - 1][i] != 0)
      hh[h - j - 1][i] = hh[h - j][i];
  // REP(i, h) REP(j, w) cout << hh[i][j] << " \n"[j==w-1];

  int ans = 0;
  REP(i, h) REP(j, w) ans = max(ans, ww[i][j] + hh[i][j] - 1);
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
// #define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
  t = v;
}

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
  for (auto &e : t)
    fill_v(e, v);
}

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, h) cin >> s[i];

  vector<vector<int>> ww(h + 5, vector<int>(w + 5, 0));
  vector<vector<int>> hh(h + 5, vector<int>(w + 5, 0));
  REP(i, h) {
    REP(j, w) {
      if (j == 0)
        ww[i][j] = (s[i][j] == '.' ? 1 : 0);
      else {
        ww[i][j] = (s[i][j] == '.' ? ww[i][j - 1] + 1 : 0);
      }
    }
  }
  REP(i, w) {
    REP(j, h) {
      if (j == 0)
        hh[j][i] = (s[j][i] == '.' ? 1 : 0);
      else {
        hh[j][i] = (s[j][i] == '.' ? hh[j - 1][i] + 1 : 0);
      }
    }
  }

  REP(i, h)
  FOR(j, 1, w) if (ww[i][w - j] != 0 && ww[i][w - j - 1] != 0)
      ww[i][w - j - 1] = ww[i][w - j];
  REP(i, w)
  FOR(j, 1, h) if (hh[h - j][i] != 0 && hh[h - j - 1][i] != 0)
      hh[h - j - 1][i] = hh[h - j][i];
  // REP(i, h) REP(j, w) cout << hh[i][j] << " \n"[j==w-1];

  int ans = 0;
  REP(i, h) REP(j, w) ans = max(ans, ww[i][j] + hh[i][j] - 1);
  cout << ans << endl;
}