Problem p03167 (C++)

Buggy submission (status: Runtime Error):
/*
    @author : srinathbalaji_99
*/

#include <bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for (long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b) / GCD(a, b)
#define ff first
#define ss second
#define pall(a)                                                                \
  REP(i, sizeof(a) / sizeof(a[0])) cout << a[i] << " ";                        \
  cout << endl;
#define pvall(v)                                                               \
  REP(i, v.size()) cout << v[i] << " ";                                        \
  cout << endl;
#define gall(a, n) REP(i, n) cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;

using namespace std;

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

LL dp[1001][1001];

int main() {
  fast();

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  LL t, n, i, j, k, x, y, c, m;
  cin >> n >> m;
  LL a[n][m];
  char ch;
  REP(i, n) {
    REP(j, m) {
      cin >> ch;
      if (ch == '.') {
        a[i][j] = 1;
      } else {
        a[i][j] = 0;
      }
    }
  }
  REP(i, n) {
    REP(j, m) {
      if (i == 0 && j == 0) {
        dp[i][j] = 1;
        continue;
      }
      if (i == 0) {
        if (a[i][j] == 0) {
          dp[i][j] = 0;
        } else {
          dp[i][j] = dp[i][j - 1];
        }
        continue;
      }
      if (j == 0) {
        if (a[i][j] == 0) {
          dp[i][j] = 0;
        } else {
          dp[i][j] = dp[i - 1][j];
        }
        continue;
      }
      if (a[i][j] == 0) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = ((dp[i - 1][j] % MOD) + (dp[i][j - 1] % MOD)) % MOD;
      }
    }
  }

  // REP(i, n){
  //     REP(j, m){
  //         cout << dp[i][j] << " ";
  //     }
  //     cout << endl;
  // }
  cout << dp[n - 1][m - 1];
}

Fixed submission:
/*
    @author : srinathbalaji_99
*/

#include <bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for (long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b) / GCD(a, b)
#define ff first
#define ss second
#define pall(a)                                                                \
  REP(i, sizeof(a) / sizeof(a[0])) cout << a[i] << " ";                        \
  cout << endl;
#define pvall(v)                                                               \
  REP(i, v.size()) cout << v[i] << " ";                                        \
  cout << endl;
#define gall(a, n) REP(i, n) cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;

using namespace std;

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

LL dp[1001][1001];

int main() {
  fast();

  LL t, n, i, j, k, x, y, c, m;
  cin >> n >> m;
  LL a[n][m];
  char ch;
  REP(i, n) {
    REP(j, m) {
      cin >> ch;
      if (ch == '.') {
        a[i][j] = 1;
      } else {
        a[i][j] = 0;
      }
    }
  }
  REP(i, n) {
    REP(j, m) {
      if (i == 0 && j == 0) {
        dp[i][j] = 1;
        continue;
      }
      if (i == 0) {
        if (a[i][j] == 0) {
          dp[i][j] = 0;
        } else {
          dp[i][j] = dp[i][j - 1];
        }
        continue;
      }
      if (j == 0) {
        if (a[i][j] == 0) {
          dp[i][j] = 0;
        } else {
          dp[i][j] = dp[i - 1][j];
        }
        continue;
      }
      if (a[i][j] == 0) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = ((dp[i - 1][j] % MOD) + (dp[i][j - 1] % MOD)) % MOD;
      }
    }
  }

  // REP(i, n){
  //     REP(j, m){
  //         cout << dp[i][j] << " ";
  //     }
  //     cout << endl;
  // }
  cout << dp[n - 1][m - 1];
}