Problem p03014 (C++)

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF INT_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()

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

  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++)
    cin >> S[i];
  vector<vector<ll>> sum(H, vector<ll>(W));
  for (int i = 0; i < H; i++) {
    vector<ll> tor(W, 0);
    for (int j = 0; j < W; j++) {
      if (j == 0 && S[i][j] == '.')
        tor[j] = 1;
      else if (j != 0 && S[i][j] == '.')
        tor[j] = tor[j - 1] + 1;
      else
        tor[j] = 0;
    }
    vector<ll> tol(W, 0);
    for (int j = W - 1; j >= 0; j--) {
      if (j == W - 1 && S[i][j] == '.')
        tol[j] = 1;
      else if (j != W - 1 && S[i][j] == '.')
        tol[j] = tol[j + 1] + 1;
      else
        tol[j] = 0;
    }
    vector<ll> res(W, 0);
    for (int j = 0; j < W; j++) {
      res[j] = max(tol[j], tor[j]);
    }
    for (int j = 1; j < W; j++) {
      if (S[i][j] == '.')
        res[j] = max(res[j - 1], res[j]);
    }
    for (int j = W - 2; j >= 0; j--) {
      if (S[i][j] == '.')
        res[j] = max(res[j + 1], res[j]);
    }
    sum[i] = res;
  }

  for (int i = 0; i < W; i++) {
    vector<ll> tod(H, 0);
    for (int j = 0; j < H; j++) {
      if (j == 0 && S[j][i] == '.')
        tod[j] = 1;
      else if (j != 0 && S[j][i] == '.')
        tod[j] = tod[j - 1] + 1;
      else
        tod[j] = 0;
    }
    vector<ll> tou(H, 0);
    for (int j = H - 1; j >= 0; j--) {
      if (j == H - 1 && S[j][i] == '.')
        tou[j] = 1;
      else if (j != H - 1 && S[j][i] == '.')
        tou[j] = tou[j + 1] + 1;
      else
        tou[j] = 0;
    }
    vector<ll> res(W);
    for (int j = 0; j < H; j++) {
      res[j] = max(tod[j], tou[j]);
    }
    for (int j = 1; j < H; j++) {
      if (S[j][i] == '.')
        res[j] = max(res[j - 1], res[j]);
    }
    for (int j = H - 2; j >= 0; j--) {
      if (S[j][i] == '.')
        res[j] = max(res[j + 1], res[j]);
    }
    for (int j = 0; j < H; j++) {
      sum[j][i] += res[j];
    }
  }
  ll ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (sum[i][j] != 0)
        sum[i][j]--;
      ans = max(ans, sum[i][j]);
      // cout<<sum[i][j]<<" ";
    }
    // cout<<endl;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define INF INT_MAX
#define MOD 1000000007
#define rng(a) a.begin(), a.end()
#define rrng(a) a.end(), a.begin()

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

  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++)
    cin >> S[i];
  vector<vector<ll>> sum(H, vector<ll>(W));
  for (int i = 0; i < H; i++) {
    vector<ll> tor(W, 0);
    for (int j = 0; j < W; j++) {
      if (j == 0 && S[i][j] == '.')
        tor[j] = 1;
      else if (j != 0 && S[i][j] == '.')
        tor[j] = tor[j - 1] + 1;
      else
        tor[j] = 0;
    }
    vector<ll> tol(W, 0);
    for (int j = W - 1; j >= 0; j--) {
      if (j == W - 1 && S[i][j] == '.')
        tol[j] = 1;
      else if (j != W - 1 && S[i][j] == '.')
        tol[j] = tol[j + 1] + 1;
      else
        tol[j] = 0;
    }
    vector<ll> res(W, 0);
    for (int j = 0; j < W; j++) {
      res[j] = max(tol[j], tor[j]);
    }
    for (int j = 1; j < W; j++) {
      if (S[i][j] == '.')
        res[j] = max(res[j - 1], res[j]);
    }
    for (int j = W - 2; j >= 0; j--) {
      if (S[i][j] == '.')
        res[j] = max(res[j + 1], res[j]);
    }
    sum[i] = res;
  }

  for (int i = 0; i < W; i++) {
    vector<ll> tod(H, 0);
    for (int j = 0; j < H; j++) {
      if (j == 0 && S[j][i] == '.')
        tod[j] = 1;
      else if (j != 0 && S[j][i] == '.')
        tod[j] = tod[j - 1] + 1;
      else
        tod[j] = 0;
    }
    vector<ll> tou(H, 0);
    for (int j = H - 1; j >= 0; j--) {
      if (j == H - 1 && S[j][i] == '.')
        tou[j] = 1;
      else if (j != H - 1 && S[j][i] == '.')
        tou[j] = tou[j + 1] + 1;
      else
        tou[j] = 0;
    }
    vector<ll> res(H);
    for (int j = 0; j < H; j++) {
      res[j] = max(tod[j], tou[j]);
    }
    for (int j = 1; j < H; j++) {
      if (S[j][i] == '.')
        res[j] = max(res[j - 1], res[j]);
    }
    for (int j = H - 2; j >= 0; j--) {
      if (S[j][i] == '.')
        res[j] = max(res[j + 1], res[j]);
    }
    for (int j = 0; j < H; j++) {
      sum[j][i] += res[j];
    }
  }
  ll ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (sum[i][j] != 0)
        sum[i][j]--;
      ans = max(ans, sum[i][j]);
      // cout<<sum[i][j]<<" ";
    }
    // cout<<endl;
  }
  cout << ans << endl;
  return 0;
}