Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define debug(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

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

  vector<vector<LL>> left(h, vector<LL>(w, 0));
  vector<vector<LL>> right(h, vector<LL>(w, 0));
  vector<vector<LL>> up(h, vector<LL>(w, 0));
  vector<vector<LL>> down(h, vector<LL>(w, 0));

  rep(y, h) {
    int acc = 0;
    rep(x, w) {
      if (s[x][y] == '#') {
        acc = 0;
        continue;
      }
      acc++;
      left[y][x] = acc;
    }
  }
  rep(y, h) {
    int acc = 0;
    for (int x = w - 1; x >= 0; x--) {
      if (s[y][x] == '#') {
        acc = 0;
        continue;
      }
      acc++;
      right[y][x] = acc;
    }
  }
  rep(x, w) {
    int acc = 0;
    rep(y, h) {
      if (s[y][x] == '#') {
        acc = 0;
        continue;
      }
      acc++;
      up[y][x] = acc;
    }
  }
  rep(x, w) {
    int acc = 0;
    for (int y = h - 1; y >= 0; y--) {
      if (s[y][x] == '#') {
        acc = 0;
        continue;
      }
      acc++;
      down[y][x] = acc;
    }
  }
  LL ans = 0;
  rep(y, h) {
    rep(x, w) {
      ans = max(ans, left[y][x] + right[y][x] + up[y][x] + down[y][x] - 3);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define debug(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

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

  vector<vector<LL>> left(h, vector<LL>(w, 0));
  vector<vector<LL>> right(h, vector<LL>(w, 0));
  vector<vector<LL>> up(h, vector<LL>(w, 0));
  vector<vector<LL>> down(h, vector<LL>(w, 0));

  rep(y, h) {
    int acc = 0;
    rep(x, w) {
      if (s[y][x] == '#') {
        acc = 0;
        continue;
      }
      acc++;
      left[y][x] = acc;
    }
  }
  rep(y, h) {
    int acc = 0;
    for (int x = w - 1; x >= 0; x--) {
      if (s[y][x] == '#') {
        acc = 0;
        continue;
      }
      acc++;
      right[y][x] = acc;
    }
  }
  rep(x, w) {
    int acc = 0;
    rep(y, h) {
      if (s[y][x] == '#') {
        acc = 0;
        continue;
      }
      acc++;
      up[y][x] = acc;
    }
  }
  rep(x, w) {
    int acc = 0;
    for (int y = h - 1; y >= 0; y--) {
      if (s[y][x] == '#') {
        acc = 0;
        continue;
      }
      acc++;
      down[y][x] = acc;
    }
  }
  LL ans = 0;
  rep(y, h) {
    rep(x, w) {
      ans = max(ans, left[y][x] + right[y][x] + up[y][x] + down[y][x] - 3);
    }
  }
  cout << ans << endl;
  return 0;
}