Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template <class T> void dump_array_impl(const T &a) {
  bool first = true;
  for (auto &&x : a) {
    if (!first)
      cout << ", ";
    else
      first = false;
    cout << x;
  }
}
#define debug_array(a)                                                         \
  cout << (#a) << ": ";                                                        \
  dump_array_impl(a);                                                          \
  cout << endl
#else
#define debug(var)                                                             \
  {}
#define debug_array(a)                                                         \
  {}
#endif
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
  v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n) {
  v = vector<T>(n);
  for (lli i = 0; i < n; ++i)
    cin >> v[i];
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs

const lli mod = 1e9 + 7;
lli h, w;
vector<string> bd;
vector<vector<lli>> c;
int main() {
  cin >> h >> w;
  read_n(bd, h);
  for (lli i = 0; i < h; ++i)
    bd[i].push_back('#');
  bd[h] = string(w + 1, '#');
  for (lli i = 0; i < h + 1; ++i)
    c.emplace_back(w + 1, 0);
  c[0][0] = 1;
  queue<pair<lli, lli>> q;
  q.emplace(0, 0);
  while (!q.empty()) {
    auto p = q.front();
    lli x = p.first, y = p.second;
    q.pop();
    if (bd[y][x + 1] != '#') {
      c[y][x + 1] = (c[y][x] + c[y][x + 1]) % mod;
      if (bd[y][x + 1] == '.') {
        q.emplace(x + 1, y);
        bd[y][x + 1] = '*';
      }
    }
    if (bd[y + 1][x] != '#') {
      c[y + 1][x] = (c[y][x] + c[y + 1][x]) % mod;
      if (bd[y + 1][x] == '.') {
        q.emplace(x, y + 1);
        bd[y + 1][x] = '*';
      }
    }
  }
  cout << c[h - 1][w - 1] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template <class T> void dump_array_impl(const T &a) {
  bool first = true;
  for (auto &&x : a) {
    if (!first)
      cout << ", ";
    else
      first = false;
    cout << x;
  }
}
#define debug_array(a)                                                         \
  cout << (#a) << ": ";                                                        \
  dump_array_impl(a);                                                          \
  cout << endl
#else
#define debug(var)                                                             \
  {}
#define debug_array(a)                                                         \
  {}
#endif
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
  v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n) {
  v = vector<T>(n);
  for (lli i = 0; i < n; ++i)
    cin >> v[i];
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs

const lli mod = 1e9 + 7;
lli h, w;
vector<string> bd;
vector<vector<lli>> c;
int main() {
  cin >> h >> w;
  read_n(bd, h);
  for (lli i = 0; i < h; ++i)
    bd[i].push_back('#');
  bd.emplace_back(w + 1, '#');
  for (lli i = 0; i < h + 1; ++i)
    c.emplace_back(w + 1, 0);
  c[0][0] = 1;
  queue<pair<lli, lli>> q;
  q.emplace(0, 0);
  while (!q.empty()) {
    auto p = q.front();
    lli x = p.first, y = p.second;
    q.pop();
    if (bd[y][x + 1] != '#') {
      c[y][x + 1] = (c[y][x] + c[y][x + 1]) % mod;
      if (bd[y][x + 1] == '.') {
        q.emplace(x + 1, y);
        bd[y][x + 1] = '*';
      }
    }
    if (bd[y + 1][x] != '#') {
      c[y + 1][x] = (c[y][x] + c[y + 1][x]) % mod;
      if (bd[y + 1][x] == '.') {
        q.emplace(x, y + 1);
        bd[y + 1][x] = '*';
      }
    }
  }
  cout << c[h - 1][w - 1] << endl;
  return 0;
}