Problem p03014 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <string>
#include <vector>

#define ll long long

using namespace std;

int main() {

  int h, w;
  cin >> h >> w;
  vector<string> s;
  vector<vector<int>> snh;
  vector<vector<int>> snw;

  for (int i = 0; i < h; i++) {
    string tmp;
    cin >> tmp;

    s.push_back(tmp);

    vector<int> tmpv;
    int tmpcount = 0;
    for (int j = 0; j < w; j++) {
      if (tmp[j] == '.') {
        tmpcount++;
        tmpv.push_back(tmpcount);
      } else {
        tmpcount = 0;
        tmpv.push_back(tmpcount);
      }
    }

    tmpcount = 0;

    for (int j = w - 1; j > -1; j--) {
      if (tmpv[j] == 0) {
        tmpcount = 0;
      } else {
        tmpcount = max(tmpcount, tmpv[j]);
        tmpv[j] = tmpcount;
      }
    }

    snh.push_back(tmpv);
  }

  for (int i = 0; i < w; i++) {
    vector<int> tmpv;
    int tmpcount = 0;
    for (int j = 0; j < h; j++) {
      if (s[j][i] == '.') {
        tmpcount++;
        tmpv.push_back(tmpcount);

      } else {
        tmpcount = 0;
        tmpv.push_back(tmpcount);
      }
    }

    tmpcount = 0;

    for (int j = h - 1; j > -1; j--) {
      if (tmpv[j] == 0) {
        tmpcount = 0;
      } else {
        tmpcount = max(tmpcount, tmpv[j]);
        tmpv[j] = tmpcount;
      }
    }

    snw.push_back(tmpv);
  }

  int ans = 0;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {

      ans = max(ans, snh[i][j] + snw[j][i]);
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {

      cerr << snh[i][j] << " ";
    }
    cerr << endl;
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {

      cerr << snw[j][i] << " ";
    }
    cerr << endl;
  }

  cout << ans - 1 << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <string>
#include <vector>

#define ll long long

using namespace std;

int main() {

  int h, w;
  cin >> h >> w;
  vector<string> s;
  vector<vector<int>> snh;
  vector<vector<int>> snw;

  for (int i = 0; i < h; i++) {
    string tmp;
    cin >> tmp;

    s.push_back(tmp);

    vector<int> tmpv;
    int tmpcount = 0;
    for (int j = 0; j < w; j++) {
      if (tmp[j] == '.') {
        tmpcount++;
        tmpv.push_back(tmpcount);
      } else {
        tmpcount = 0;
        tmpv.push_back(tmpcount);
      }
    }

    tmpcount = 0;

    for (int j = w - 1; j > -1; j--) {
      if (tmpv[j] == 0) {
        tmpcount = 0;
      } else {
        tmpcount = max(tmpcount, tmpv[j]);
        tmpv[j] = tmpcount;
      }
    }

    snh.push_back(tmpv);
  }

  for (int i = 0; i < w; i++) {
    vector<int> tmpv;
    int tmpcount = 0;
    for (int j = 0; j < h; j++) {
      if (s[j][i] == '.') {
        tmpcount++;
        tmpv.push_back(tmpcount);

      } else {
        tmpcount = 0;
        tmpv.push_back(tmpcount);
      }
    }

    tmpcount = 0;

    for (int j = h - 1; j > -1; j--) {
      if (tmpv[j] == 0) {
        tmpcount = 0;
      } else {
        tmpcount = max(tmpcount, tmpv[j]);
        tmpv[j] = tmpcount;
      }
    }

    snw.push_back(tmpv);
  }

  int ans = 0;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {

      ans = max(ans, snh[i][j] + snw[j][i]);
    }
  }

  cout << ans - 1 << endl;

  return 0;
}