Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ll long long
#define M 1000000007
#define pb emplace_back
#define p_q priority_queue
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll) x.size()
#define endl '\n'
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a, n, b)                                                           \
  for (ll int i = 0; i < n; i++)                                               \
    a[i] = 0;
#define cset(a) __builtin_popcountll(a)
#define hell (ull)1e9
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
    cerr << endl;                                                              \
  }
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

bool g[(ll)1e3 + 2][(ll)1e3 + 2];
int dp[(ll)1e3 + 2][(ll)1e3 + 2];
signed main(void) {
  ios
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int h, w;
  cin >> h >> w;
  dp[1][1] = 1;
  rep(i, 1, h + 1) rep(j, 1, w + 1) {
    char c;
    cin >> c;
    if (c == '#')
      g[i][j] = 1;
  }
  rep(i, 1, h + 1) rep(j, 1, w + 1) {
    if (i == 1 && j == 1)
      continue;
    if (g[i][j])
      continue;
    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % M;
  }
  cout << dp[h][w] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ll long long
#define M 1000000007
#define pb emplace_back
#define p_q priority_queue
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll) x.size()
#define endl '\n'
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a, n, b)                                                           \
  for (ll int i = 0; i < n; i++)                                               \
    a[i] = 0;
#define cset(a) __builtin_popcountll(a)
#define hell (ull)1e9
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
    cerr << endl;                                                              \
  }
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

bool g[(ll)1e3 + 2][(ll)1e3 + 2];
int dp[(ll)1e3 + 2][(ll)1e3 + 2];
signed main(void) {
  ios int h, w;
  cin >> h >> w;
  dp[1][1] = 1;
  rep(i, 1, h + 1) rep(j, 1, w + 1) {
    char c;
    cin >> c;
    if (c == '#')
      g[i][j] = 1;
  }
  rep(i, 1, h + 1) rep(j, 1, w + 1) {
    if (i == 1 && j == 1)
      continue;
    if (g[i][j])
      continue;
    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % M;
  }
  cout << dp[h][w] << endl;
}