Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
// typedef long long unsigned int ll;
typedef long long ll;
typedef pair<ll, ll> edge;
typedef tuple<ll, ll, ll> tp;

int main() {
  ll h, w;
  cin >> h >> w;
  string S[h];
  for (int i = 0; i < h; i++)
    cin >> S[h];
  cout << S[0][0] << endl;
  int R[h][w];
  int L[h][w];
  int U[h][w];
  int D[h][w];
  for (int i = 0; i < h; i++) {
    if (S[i][w - 1] == '.')
      R[i][w - 1] = 1;
    else
      R[i][w - 1] = 0;
    if (S[i][0] == '.')
      L[i][0] = 1;
    else
      L[i][0] = 0;
  }
  for (int i = 0; i < w; i++) {
    if (S[h - 1][i] == '.')
      D[h - 1][i] = 1;
    else
      D[h - 1][i] = 0;
    if (S[0][i] == '.')
      U[0][i] = 1;
    else
      U[0][i] = 0;
  }

  for (int i = 1; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (S[j][w - 1 - i] == '.')
        R[j][w - 1 - i] = R[j][w - i] + 1;
      else
        R[j][w - 1 - i] = 0;
      if (S[j][i] == '.')
        L[j][i] = L[j][i - 1] + 1;
      else
        L[j][i] = 0;
    }
  }
  for (int i = 1; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (S[h - 1 - i][j] == '.')
        D[h - 1 - i][j] = D[h - i][j] + 1;
      else
        D[h - 1 - i][j] = 0;
      if (S[i][j] == '.')
        U[i][j] = U[i - 1][j] + 1;
      else
        U[i][j] = 0;
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, R[i][j] + L[i][j] + U[i][j] + D[i][j]);
    }
  }
  cout << ans - 3 << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
// typedef long long unsigned int ll;
typedef long long ll;
typedef pair<ll, ll> edge;
typedef tuple<ll, ll, ll> tp;

int main() {
  ll h, w;
  cin >> h >> w;
  string S[h];
  for (int i = 0; i < h; i++)
    cin >> S[i];
  // cout << S[0][0] << endl;

  int R[h][w];
  int L[h][w];
  int U[h][w];
  int D[h][w];
  for (int i = 0; i < h; i++) {
    if (S[i][w - 1] == '.')
      R[i][w - 1] = 1;
    else
      R[i][w - 1] = 0;
    if (S[i][0] == '.')
      L[i][0] = 1;
    else
      L[i][0] = 0;
  }
  for (int i = 0; i < w; i++) {
    if (S[h - 1][i] == '.')
      D[h - 1][i] = 1;
    else
      D[h - 1][i] = 0;
    if (S[0][i] == '.')
      U[0][i] = 1;
    else
      U[0][i] = 0;
  }

  for (int i = 1; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (S[j][w - 1 - i] == '.')
        R[j][w - 1 - i] = R[j][w - i] + 1;
      else
        R[j][w - 1 - i] = 0;
      if (S[j][i] == '.')
        L[j][i] = L[j][i - 1] + 1;
      else
        L[j][i] = 0;
    }
  }
  for (int i = 1; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (S[h - 1 - i][j] == '.')
        D[h - 1 - i][j] = D[h - i][j] + 1;
      else
        D[h - 1 - i][j] = 0;
      if (S[i][j] == '.')
        U[i][j] = U[i - 1][j] + 1;
      else
        U[i][j] = 0;
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, R[i][j] + L[i][j] + U[i][j] + D[i][j]);
    }
  }
  cout << ans - 3 << endl;
}