Problem p03014 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name)                                                               \
  int(name);                                                                   \
  scanf("%d", &(name))
#define GI2(name1, name2)                                                      \
  int(name1), (name2);                                                         \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3)                                               \
  int(name1), (name2), (name3);                                                \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)                                                        \
  vector<int>(name)(size);                                                     \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name)                                                               \
  string(name);                                                                \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) { return s; }

template <class T> string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail> void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(H, W);
  vector<string> S(H);
  vector<int> yoko(H * W), tate(H * W);
  FOR(i, H) cin >> S[i];
  FOR(i, H) {
    int now_count = 0;
    FOR(j, W) {
      if (S[i][j] == '.') {
        now_count++;
      } else {
        for (int x = j - now_count; x < j; ++x) {
          yoko[i * W + x] = now_count;
        }
        now_count = 0;
      }
    }
    if (now_count > 0) {
      for (int x = W - now_count; x < W; ++x) {
        yoko[i * W + x] = now_count;
      }
    }
  }
  FOR(j, W) {
    int now_count = 0;
    FOR(i, H) {
      if (S[i][j] == '.') {
        now_count++;
      } else {
        for (int y = i - now_count; y < i; ++y) {
          tate[y * W + j] = now_count;
        }
        now_count = 0;
      }
    }
    if (now_count > 0) {
      for (int y = H - now_count; y < W; ++y) {
        tate[y * W + j] = now_count;
      }
    }
  }
  int ans = 0;
  FOR(i, H) {
    FOR(j, W) {
      ans = max(ans, yoko[i * W + j] + tate[i * W + j] -
                         (yoko[i * W + j] > 0 && tate[i * W + j] ? 1 : 0));
    }
  }
  print(ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name)                                                               \
  int(name);                                                                   \
  scanf("%d", &(name))
#define GI2(name1, name2)                                                      \
  int(name1), (name2);                                                         \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3)                                               \
  int(name1), (name2), (name3);                                                \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)                                                        \
  vector<int>(name)(size);                                                     \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name)                                                               \
  string(name);                                                                \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) { return s; }

template <class T> string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail> void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(H, W);
  vector<string> S(H);
  vector<int> yoko(H * W), tate(H * W);
  FOR(i, H) cin >> S[i];
  FOR(i, H) {
    int now_count = 0;
    FOR(j, W) {
      if (S[i][j] == '.') {
        now_count++;
      } else {
        for (int x = j - now_count; x < j; ++x) {
          yoko[i * W + x] = now_count;
        }
        now_count = 0;
      }
    }
    if (now_count > 0) {
      for (int x = W - now_count; x < W; ++x) {
        yoko[i * W + x] = now_count;
      }
    }
  }
  FOR(j, W) {
    int now_count = 0;
    FOR(i, H) {
      if (S[i][j] == '.') {
        now_count++;
      } else {
        for (int y = i - now_count; y < i; ++y) {
          tate[y * W + j] = now_count;
        }
        now_count = 0;
      }
    }
    if (now_count > 0) {
      for (int y = H - now_count; y < H; ++y) {
        tate[y * W + j] = now_count;
      }
    }
  }
  int ans = 0;
  FOR(i, H) {
    FOR(j, W) {
      ans = max(ans, yoko[i * W + j] + tate[i * W + j] -
                         (yoko[i * W + j] > 0 && tate[i * W + j] ? 1 : 0));
    }
  }
  print(ans);
  return 0;
}