Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define vllin(x, n)                                                            \
  vll(x)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n)                                                        \
  vll(a)(n);                                                                   \
  vll(b)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i]; }
#define vllin3(a, b, c, n)                                                     \
  vll(a)(n);                                                                   \
  vll(b)(n);                                                                   \
  vll(c)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i] >> (c)[i]; }
#define vlling(x, n)                                                           \
  (x).assign(n, 0);                                                            \
  FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vlling2(a, b, n)                                                       \
  (a).assign(n, 0);                                                            \
  (b).assign(n, 0);                                                            \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i]; }
#define vlling3(a, b, c, n)                                                    \
  (a).assign(n, 0);                                                            \
  (b).assign(n, 0);                                                            \
  (c).assign(n, 0);                                                            \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i] >> (c)[i]; }
#define vpl4in(x, n)                                                           \
  vpl4(x)((n), mp(0, 0));                                                      \
  FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))

ll MOD = 1000000007;

signed main() {
  llin(h);
  llin(w);
  vector<str> s(h, "");
  FOR(i, 0, h - 1) { cin >> s[i]; }
  vvll ws(h, vll(w, 0));
  vvll hs(h, vll(w, 0));
  vvll wr(h, vll(w + 1, 0));
  vvll hr(h + 1, vll(w, 0));
  ll t = 0;
  ll c = 0;
  FOR(i, 0, h - 1) {
    t = 1;
    c = 0;
    FOR(j, 0, w - 1) {
      if (s[i][j] == '#') {
        wr[i][t] = c;
        t++;
        c = 0;
      } else {
        ws[i][j] = t;
        c++;
      }
    }
    wr[i][t] = c;
  }
  FOR(j, 0, w - 1) {
    t = 1;
    c = 0;
    FOR(i, 0, h - 1) {
      if (s[i][j] == '#') {
        hr[t][j] = c;
        t++;
        c = 0;
      } else {
        hs[i][j] = t;
        c++;
      }
    }
    hr[t][j] = c;
  }
  ll k = 0;
  FOR(i, 0, h - 1) {
    FOR(j, 0, w - 1) {
      if (s[i][j] == '.') {
        k = max(wr[i][ws[i][j]] + hr[hs[i][j]][j], k);
      }
    }
  }
  sal(k - 1)
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define vllin(x, n)                                                            \
  vll(x)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n)                                                        \
  vll(a)(n);                                                                   \
  vll(b)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i]; }
#define vllin3(a, b, c, n)                                                     \
  vll(a)(n);                                                                   \
  vll(b)(n);                                                                   \
  vll(c)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i] >> (c)[i]; }
#define vlling(x, n)                                                           \
  (x).assign(n, 0);                                                            \
  FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vlling2(a, b, n)                                                       \
  (a).assign(n, 0);                                                            \
  (b).assign(n, 0);                                                            \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i]; }
#define vlling3(a, b, c, n)                                                    \
  (a).assign(n, 0);                                                            \
  (b).assign(n, 0);                                                            \
  (c).assign(n, 0);                                                            \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> (b)[i] >> (c)[i]; }
#define vpl4in(x, n)                                                           \
  vpl4(x)((n), mp(0, 0));                                                      \
  FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))

ll MOD = 1000000007;

signed main() {
  llin(h);
  llin(w);
  vector<str> s(h, "");
  FOR(i, 0, h - 1) { cin >> s[i]; }
  vvll ws(h, vll(w, 0));
  vvll hs(h, vll(w, 0));
  vvll wr(h, vll(w + 2, 0));
  vvll hr(h + 2, vll(w, 0));
  ll t = 0;
  ll c = 0;
  FOR(i, 0, h - 1) {
    t = 1;
    c = 0;
    FOR(j, 0, w - 1) {
      if (s[i][j] == '#') {
        wr[i][t] = c;
        t++;
        c = 0;
      } else {
        ws[i][j] = t;
        c++;
      }
    }
    wr[i][t] = c;
  }
  FOR(j, 0, w - 1) {
    t = 1;
    c = 0;
    FOR(i, 0, h - 1) {
      if (s[i][j] == '#') {
        hr[t][j] = c;
        t++;
        c = 0;
      } else {
        hs[i][j] = t;
        c++;
      }
    }
    hr[t][j] = c;
  }
  ll k = 0;
  FOR(i, 0, h - 1) {
    FOR(j, 0, w - 1) {
      if (s[i][j] == '.') {
        k = max(wr[i][ws[i][j]] + hr[hs[i][j]][j], k);
      }
    }
  }
  sal(k - 1)
}