Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name, num) vector<ll> name((num), 0);
#define op(i) cout << (i) << endl;
#define ip(i) cin >> (i);
#define opN cout << "No" << endl;
#define opY cout << "Yes" << endl;
#define opP cout << "Possible" << endl;
#define opI cout << "Impossible" << endl;
#define mat(name, fnum, snum)                                                  \
  ;                                                                            \
  vector<vector<ll>> name((fnum), vector<ll>((snum), 0));
#define matC(name, fnum, snum)                                                 \
  ;                                                                            \
  vector<vector<char>> name((fnum), vector<char>((snum), 0));
#define debugP                                                                 \
  int debug_point;                                                             \
  cin >> debug_point;
#define FI first
#define SE second
const ll MOD = 1e9 + 7;
template <typename T> void putv(vector<T> &V) {
  // cout << "The elements in the vector are: " << endl;
  for (auto x : V)
    cout << x << " ";
  cout << endl;
}
ll pow_mod(ll fi, ll se, ll mod) {
  if (se == 0) {
    return 1;
  }
  if (se % 2) {
    return pow_mod(fi, se - 1, mod) * fi % mod;
  }
  ll t = pow_mod(fi, se / 2, mod);
  return t * t % mod;
}
template <class T> vector<T> getv(ll n) {
  vector<T> Vector_temp;
  rep(i, n) {
    T input;
    cin >> input;
    Vector_temp.emplace_back(input);
  }
  return Vector_temp;
}
ll gcd(ll c, ll b) {
  while (1) {
    if (c % b != 0) {
      ll tmp = b;
      b = c % b;
      c = tmp;
    } else {
      return b;
    }
  }
}

vector<pair<int, int>> Dir = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  // vector<vector<vector<ll>>> cnt(h,vector<vector<ll>>(w,vector<ll>(4)));
  vector<vector<ll>> cnt(h, vector<ll>(w, 1));
  rep(i, h) {
    rep(j, w) { cin >> s[i][j]; }
  }

  ll tmp = 0;
  rep(i, h) {
    tmp = 0;
    rep(j, w) {
      if (s[i][j] == '#') {
        tmp = j + 1;
        continue;
      }
      cnt[i][j] += j - tmp;
      // cout<<cnt[i][j][0]<<endl;
    }
  }
  rep(i, h) {
    tmp = w - 1;
    for (ll j = w - 1; j >= 0; j--) {
      if (s[i][j] == '#') {
        tmp = j - 1;
        continue;
      }
      cnt[i][j] += tmp - j;
      // cout<<cnt[i][j][1]<<endl;
    }
  }
  rep(j, w) {
    tmp = 0;
    rep(i, h) {
      if (s[i][j] == '#') {
        tmp = i + 1;
        continue;
      }
      cnt[i][j] += i - tmp;
    }
  }
  rep(j, w) {
    tmp = h - 1;
    for (int i = h - 1; i >= 0; i--) {
      if (s[i][j] == '#') {
        tmp = i - 1;
        continue;
      }
      cnt[i][j] += tmp - i;
    }
  }
  ll ans = 0;
  rep(i, h) {
    rep(j, w) {

      // rep(k,4)if(s[i][j]=='.'){tmp+=cnt[i][j][k];}

      ans = max(ans, cnt[i][j]);
    }
  }
  op(ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name, num) vector<ll> name((num), 0);
#define op(i) cout << (i) << endl;
#define ip(i) cin >> (i);
#define opN cout << "No" << endl;
#define opY cout << "Yes" << endl;
#define opP cout << "Possible" << endl;
#define opI cout << "Impossible" << endl;
#define mat(name, fnum, snum)                                                  \
  ;                                                                            \
  vector<vector<ll>> name((fnum), vector<ll>((snum), 0));
#define matC(name, fnum, snum)                                                 \
  ;                                                                            \
  vector<vector<char>> name((fnum), vector<char>((snum), 0));
#define debugP                                                                 \
  int debug_point;                                                             \
  cin >> debug_point;
#define FI first
#define SE second
const ll MOD = 1e9 + 7;
template <typename T> void putv(vector<T> &V) {
  // cout << "The elements in the vector are: " << endl;
  for (auto x : V)
    cout << x << " ";
  cout << endl;
}
ll pow_mod(ll fi, ll se, ll mod) {
  if (se == 0) {
    return 1;
  }
  if (se % 2) {
    return pow_mod(fi, se - 1, mod) * fi % mod;
  }
  ll t = pow_mod(fi, se / 2, mod);
  return t * t % mod;
}
template <class T> vector<T> getv(ll n) {
  vector<T> Vector_temp;
  rep(i, n) {
    T input;
    cin >> input;
    Vector_temp.emplace_back(input);
  }
  return Vector_temp;
}
ll gcd(ll c, ll b) {
  while (1) {
    if (c % b != 0) {
      ll tmp = b;
      b = c % b;
      c = tmp;
    } else {
      return b;
    }
  }
}

vector<pair<int, int>> Dir = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> s(h);
  // vector<vector<vector<ll>>> cnt(h,vector<vector<ll>>(w,vector<ll>(4)));
  vector<vector<ll>> cnt(h, vector<ll>(w, 1));
  rep(i, h) { cin >> s[i]; }

  ll tmp = 0;
  rep(i, h) {
    tmp = 0;
    rep(j, w) {
      if (s[i][j] == '#') {
        tmp = j + 1;
        continue;
      }
      cnt[i][j] += j - tmp;
      // cout<<cnt[i][j][0]<<endl;
    }
  }
  rep(i, h) {
    tmp = w - 1;
    for (ll j = w - 1; j >= 0; j--) {
      if (s[i][j] == '#') {
        tmp = j - 1;
        continue;
      }
      cnt[i][j] += tmp - j;
      // cout<<cnt[i][j][1]<<endl;
    }
  }
  rep(j, w) {
    tmp = 0;
    rep(i, h) {
      if (s[i][j] == '#') {
        tmp = i + 1;
        continue;
      }
      cnt[i][j] += i - tmp;
    }
  }
  rep(j, w) {
    tmp = h - 1;
    for (int i = h - 1; i >= 0; i--) {
      if (s[i][j] == '#') {
        tmp = i - 1;
        continue;
      }
      cnt[i][j] += tmp - i;
    }
  }
  ll ans = 0;
  rep(i, h) {
    rep(j, w) {

      // rep(k,4)if(s[i][j]=='.'){tmp+=cnt[i][j][k];}

      ans = max(ans, cnt[i][j]);
    }
  }
  op(ans);
  return 0;
}