Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT                                                                   \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);

template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; }
template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; }

ll const INF = 1LL << 60;
ll const MOD = 1000000007;
ll const MAX_N = 100;
ll const MAX_M = 100;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }

  mint operator+(const mint a) const { return mint(*this) += a; }

  mint operator-(const mint a) const { return mint(*this) -= a; }

  mint operator*(const mint a) const { return mint(*this) *= a; }

  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// int dx[2] = {1, 0};
// int dy[2] = {0, 1};
mint dp[MAX_N][MAX_M];

int main() {
  INIT;

  ll H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i, H) { cin >> a[i]; }

  rep(i, H) rep(j, W) dp[i][j] = 0;

  dp[0][0] = 1;
  rep(i, H) {
    rep(j, W) {
      if (i + 1 < H && a[i + 1][j] != '#') {
        dp[i + 1][j] += dp[i][j];
      }

      if (j + 1 < W && a[i][j + 1] != '#') {
        dp[i][j + 1] += dp[i][j];
      }
    }
  }

  // rep(i, H) {
  //     rep(j, W) { cout << dp[i][j] << " "; }
  //     cout << endl;
  // }

  cout << dp[H - 1][W - 1] << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT                                                                   \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);

template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; }
template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; }

ll const INF = 1LL << 60;
ll const MOD = 1000000007;
ll const MAX_N = 1005;
ll const MAX_M = 1005;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }

  mint operator+(const mint a) const { return mint(*this) += a; }

  mint operator-(const mint a) const { return mint(*this) -= a; }

  mint operator*(const mint a) const { return mint(*this) *= a; }

  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// int dx[2] = {1, 0};
// int dy[2] = {0, 1};
mint dp[MAX_N][MAX_M];

int main() {
  INIT;

  ll H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i, H) { cin >> a[i]; }

  rep(i, H) rep(j, W) dp[i][j] = 0;

  dp[0][0] = 1;
  rep(i, H) {
    rep(j, W) {
      if (i + 1 < H && a[i + 1][j] != '#') {
        dp[i + 1][j] += dp[i][j];
      }

      if (j + 1 < W && a[i][j + 1] != '#') {
        dp[i][j + 1] += dp[i][j];
      }
    }
  }

  // rep(i, H) {
  //     rep(j, W) { cout << dp[i][j] << " "; }
  //     cout << endl;
  // }

  cout << dp[H - 1][W - 1] << endl;

  return 0;
}