Problem p03053 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _repi(i, a, b)                                                         \
  for (int i = int(a), i##_hoge = int(b); i < i##_hoge; ++i)
#define _rep(i, n) _repi(i, 0, n)

#define overload4(_1, _2, _3, _4, name, ...) name
#define rep4(i, a, b, c)                                                       \
  for (int i = int(a), i##_hogeb = int(b), i##_hogec = int(c); i < i##_hogeb;  \
       i += i##_hogec)
#define rep1(n) rep4(i, 0, n, 1)
#define rep2(i, n) rep4(i, 0, n, 1)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define REP(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n)-1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define rrep4(i, a, b, c) for (ll i = a + (b - a - 1) / c * c; i >= a; i -= c)
#define RREP(...)                                                              \
  overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define FOREACH(i, x) for (auto &i : x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define print(x) cout << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
template <class T> using vv = vector<vector<T>>;
using vint = vector<int>;
using vvint = vv<int>;
using vll = vector<ll>;
using vvll = vv<ll>;
using vbool = vector<bool>;
using vvbool = vv<bool>;
using vchar = vector<char>;
using vvchar = vv<char>;
// clang-format off
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return 1;}return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return 1;}return 0;}
// clang-format on

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
  int H, W;
  cin >> H >> W;

  vv<char> A(H + 2, vchar(W + 2, '#'));
  REP(i, 1, H + 1) REP(j, 1, W + 1) cin >> A[i][j];

  queue<pair<pii, int>> q;
  REP(i, 1, H + 1) REP(j, 1, W + 1) {
    if (A[i][j] == '#')
      q.push(mp(mp(i, j), 0));
  }

  int x, y, c;
  while (!q.empty()) {
    auto now = q.front();
    q.pop();
    y = now.first.first;
    x = now.first.second;
    c = now.second;
    REP(4) {
      if (A[x + dx[i]][y + dy[i]] == '.') {
        q.push(mp(mp(x + dx[i], y + dy[i]), c + 1));
        A[x + dx[i]][y + dy[i]] = '#';
      }
    }
  }
  print(c);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _repi(i, a, b)                                                         \
  for (int i = int(a), i##_hoge = int(b); i < i##_hoge; ++i)
#define _rep(i, n) _repi(i, 0, n)

#define overload4(_1, _2, _3, _4, name, ...) name
#define rep4(i, a, b, c)                                                       \
  for (int i = int(a), i##_hogeb = int(b), i##_hogec = int(c); i < i##_hogeb;  \
       i += i##_hogec)
#define rep1(n) rep4(i, 0, n, 1)
#define rep2(i, n) rep4(i, 0, n, 1)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define REP(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n)-1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define rrep4(i, a, b, c) for (ll i = a + (b - a - 1) / c * c; i >= a; i -= c)
#define RREP(...)                                                              \
  overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define FOREACH(i, x) for (auto &i : x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define print(x) cout << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
template <class T> using vv = vector<vector<T>>;
using vint = vector<int>;
using vvint = vv<int>;
using vll = vector<ll>;
using vvll = vv<ll>;
using vbool = vector<bool>;
using vvbool = vv<bool>;
using vchar = vector<char>;
using vvchar = vv<char>;
// clang-format off
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return 1;}return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return 1;}return 0;}
// clang-format on

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
  int H, W;
  cin >> H >> W;

  vv<char> A(H + 2, vchar(W + 2, '#'));
  REP(i, 1, H + 1) REP(j, 1, W + 1) cin >> A[i][j];

  queue<pair<pii, int>> q;
  REP(i, 1, H + 1) REP(j, 1, W + 1) {
    if (A[i][j] == '#')
      q.push(mp(mp(i, j), 0));
  }

  int x, y, c;
  while (!q.empty()) {
    auto now = q.front();
    q.pop();
    y = now.first.first;
    x = now.first.second;
    c = now.second;
    REP(4) {
      if (A[y + dy[i]][x + dx[i]] == '.') {
        q.push(mp(mp(y + dy[i], x + dx[i]), c + 1));
        A[y + dy[i]][x + dx[i]] = '#';
      }
    }
  }
  print(c);
}