Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable : 4996)
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const double PI = 3.14159265358979323846;
const int MAX = 1e7;
const int MOD = 1e9 + 7;

int main(int argc, char *args[]) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++)
    cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    vector<int> done(w);
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        ++l;
      }
      for (int k = 0; k < l; k++) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }
  for (int j = 0; j < w; j++) {
    vector<int> done(w);
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;
      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == '#')
          break;
        ++l;
      }
      for (int k = 0; k < l; k++) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, cnt[i][j] - 1);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable : 4996)
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const double PI = 3.14159265358979323846;
const int MAX = 1e7;
const int MOD = 1e9 + 7;

int main(int argc, char *args[]) {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++)
    cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    vector<int> done(w);
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#')
        continue;
      if (done[j])
        continue;
      int l = 0;
      while (j + l < w) {
        if (s[i][j + l] == '#')
          break;
        ++l;
      }
      for (int k = 0; k < l; k++) {
        cnt[i][j + k] += l;
        done[j + k] = 1;
      }
    }
  }
  for (int j = 0; j < w; j++) {
    vector<int> done(h);
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '#')
        continue;
      if (done[i])
        continue;
      int l = 0;
      while (i + l < h) {
        if (s[i + l][j] == '#')
          break;
        ++l;
      }
      for (int k = 0; k < l; k++) {
        cnt[i + k][j] += l;
        done[i + k] = 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans = max(ans, cnt[i][j] - 1);
    }
  }
  cout << ans << endl;
  return 0;
}