Problem p03014 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

template <typename T> T MatMaximum(vector<vector<T>> &mat) {
  vector<T> max_array;
  for (auto itr = mat.begin(); itr != mat.end(); ++itr) {
    T maximum = *max_element((*itr).begin(), (*itr).end());
    max_array.push_back(maximum);
  }
  return *max_element(max_array.begin(), max_array.end());
}

void process_vec(vector<int> &array, string hoge) {
  int size_array = array.size();
  int count = 0;
  hoge.push_back('#');
  for (int i = 0; i < size_array + 1; i++) {
    if (hoge[i] == '.') {
      count += 1;
    } else {
      for (int k = 0; k < count; k++) {
        array[i - k - 1] = count;
      }
      count = 0;
    }
  }
}

string get_vec_col(vector<string> S, int col_idx) {
  int row_len = S.size();
  string ret;
  for (int i = 0; i < row_len; i++) {
    ret.push_back(S[i][col_idx]);
  }
  return ret;
}

// 末尾に注意しないといけない
void solve(long long H, long long W, std::vector<std::string> S) {
  vector<vector<int>> horizontal_count(H, vector<int>(W, 0));
  vector<vector<int>> vertical_count(W, vector<int>(H, 0));
  for (int i = 0; i < H; i++) {
    process_vec(horizontal_count[i], S[i]);
  }
  for (int i = 0; i < W; i++) {
    process_vec(vertical_count[i], get_vec_col(S, i));
  }

  vector<vector<int>> count(H, vector<int>(W, 0));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count[i][j] = horizontal_count[i][j] + vertical_count[j][i];
    }
  }
  printf("%d\n", MatMaximum(count) - 1);
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  std::vector<std::string> S(H);
  for (int i = 0; i < H; i++) {
    std::cin >> S[i];
  }
  solve(H, W, std::move(S));
  return 0;
}


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

template <typename T> T MatMaximum(vector<vector<T>> &mat) {
  vector<T> max_array;
  for (auto itr = mat.begin(); itr != mat.end(); ++itr) {
    T maximum = *max_element((*itr).begin(), (*itr).end());
    max_array.push_back(maximum);
  }
  return *max_element(max_array.begin(), max_array.end());
}

void process_vec(vector<int> &array, string hoge) {
  int size_array = array.size();
  int count = 0;
  hoge.push_back('#');
  for (int i = 0; i < size_array + 1; i++) {
    if (hoge[i] == '.') {
      count += 1;
    } else {
      for (int k = 0; k < count; k++) {
        array[i - k - 1] = count;
      }
      count = 0;
    }
  }
}

string get_vec_col(vector<string> &S, int col_idx) {
  int row_len = S.size();
  string ret;
  for (int i = 0; i < row_len; i++) {
    ret.push_back(S[i][col_idx]);
  }
  return ret;
}

// 末尾に注意しないといけない
void solve(long long H, long long W, std::vector<std::string> S) {
  vector<vector<int>> horizontal_count(H, vector<int>(W, 0));
  vector<vector<int>> vertical_count(W, vector<int>(H, 0));
  for (int i = 0; i < H; i++) {
    process_vec(horizontal_count[i], S[i]);
  }
  for (int i = 0; i < W; i++) {
    process_vec(vertical_count[i], get_vec_col(S, i));
  }

  vector<vector<int>> count(H, vector<int>(W, 0));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count[i][j] = horizontal_count[i][j] + vertical_count[j][i];
    }
  }
  printf("%d\n", MatMaximum(count) - 1);
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  std::vector<std::string> S(H);
  for (int i = 0; i < H; i++) {
    std::cin >> S[i];
  }
  solve(H, W, std::move(S));
  return 0;
}