Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
  int h, w;
  int i, j, k;
  cin >> h >> w;
  vector<string> s(h);
  for (i = 0; i < h; ++i) {
    cin >> s.at(i);
  }
  vector<vector<int>> tate(h, vector<int>(w, 0));
  vector<vector<int>> yoko(h, vector<int>(w, 0));
  for (i = 0; i < w; ++i) {
    vector<int> v;
    for (j = 0; j < h; ++j) {
      if (s.at(j).at(i) == '#') {
        v.push_back(j);
      }
    }
    if (v.size() == 0) {
      for (j = 0; j < h; ++j) {
        tate.at(j).at(i) = h;
      }
      continue;
    }
    for (j = 0; j < v.at(0); ++j) {
      tate.at(j).at(i) = v.at(0);
    }
    tate.at(v.at(0)).at(i) = 0;
    for (k = 0; k < v.size() - 1; ++k) {
      for (j = v.at(k) + 1; j < v.at(k + 1); ++j) {
        tate.at(j).at(i) = v.at(k + 1) - v.at(k) - 1;
      }
      tate.at(v.at(k + 1)).at(i) = 0;
    }
    for (k = v.at(v.size() - 1) + 1; k < h; ++k) {
      tate.at(k).at(i) = h - 1 - v.at(v.size() - 1);
    }
  }
  for (i = 0; i < h; ++i) {
    vector<int> v;
    for (j = 0; j < w; ++j) {
      if (s.at(i).at(j) == '#') {
        v.push_back(j);
      }
    }
    if (v.size() == 0) {
      for (j = 0; j < h; ++j) {
        yoko.at(i).at(j) = w;
      }
      continue;
    }
    for (j = 0; j < v.at(0); ++j) {
      yoko.at(i).at(j) = v.at(0);
    }
    yoko.at(i).at(v.at(0)) = 0;
    for (k = 0; k < v.size() - 1; ++k) {
      for (j = v.at(k) + 1; j < v.at(k + 1); ++j) {
        yoko.at(i).at(j) = v.at(k + 1) - v.at(k) - 1;
      }
      yoko.at(i).at(v.at(k + 1)) = 0;
    }
    for (k = v.at(v.size() - 1) + 1; k < w; ++k) {
      yoko.at(i).at(k) = w - 1 - v.at(v.size() - 1);
    }
  }
  int ans = 0;
  for (i = 0; i < h; ++i) {
    for (j = 0; j < w; ++j) {
      if (ans < tate.at(i).at(j) + yoko.at(i).at(j) - 1) {
        ans = tate.at(i).at(j) + yoko.at(i).at(j) - 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
  int h, w;
  int i, j, k;
  cin >> h >> w;
  vector<string> s(h);
  for (i = 0; i < h; ++i) {
    cin >> s.at(i);
  }
  vector<vector<int>> tate(h, vector<int>(w, 0));
  vector<vector<int>> yoko(h, vector<int>(w, 0));
  for (i = 0; i < w; ++i) {
    vector<int> v;
    for (j = 0; j < h; ++j) {
      if (s.at(j).at(i) == '#') {
        v.push_back(j);
      }
    }
    if (v.size() == 0) {
      for (j = 0; j < h; ++j) {
        tate.at(j).at(i) = h;
      }
      continue;
    }
    for (j = 0; j < v.at(0); ++j) {
      tate.at(j).at(i) = v.at(0);
    }
    tate.at(v.at(0)).at(i) = 0;
    for (k = 0; k < v.size() - 1; ++k) {
      for (j = v.at(k) + 1; j < v.at(k + 1); ++j) {
        tate.at(j).at(i) = v.at(k + 1) - v.at(k) - 1;
      }
      tate.at(v.at(k + 1)).at(i) = 0;
    }
    for (k = v.at(v.size() - 1) + 1; k < h; ++k) {
      tate.at(k).at(i) = h - 1 - v.at(v.size() - 1);
    }
  }
  for (i = 0; i < h; ++i) {
    vector<int> v;
    for (j = 0; j < w; ++j) {
      if (s.at(i).at(j) == '#') {
        v.push_back(j);
      }
    }
    if (v.size() == 0) {
      for (j = 0; j < w; ++j) {
        yoko.at(i).at(j) = w;
      }
      continue;
    }
    for (j = 0; j < v.at(0); ++j) {
      yoko.at(i).at(j) = v.at(0);
    }
    yoko.at(i).at(v.at(0)) = 0;
    for (k = 0; k < v.size() - 1; ++k) {
      for (j = v.at(k) + 1; j < v.at(k + 1); ++j) {
        yoko.at(i).at(j) = v.at(k + 1) - v.at(k) - 1;
      }
      yoko.at(i).at(v.at(k + 1)) = 0;
    }
    for (k = v.at(v.size() - 1) + 1; k < w; ++k) {
      yoko.at(i).at(k) = w - 1 - v.at(v.size() - 1);
    }
  }
  int ans = 0;
  for (i = 0; i < h; ++i) {
    for (j = 0; j < w; ++j) {
      if (ans < tate.at(i).at(j) + yoko.at(i).at(j) - 1) {
        ans = tate.at(i).at(j) + yoko.at(i).at(j) - 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}