Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define fastread                                                               \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define print(a)                                                               \
  for (auto x : a)                                                             \
    cout << x << ' ';                                                          \
  cout << endl;
#define printM(b)                                                              \
  for (auto y : b) {                                                           \
    print(y);                                                                  \
  }
#define printP(p) cout << p.first << ' ' << p.second << endl;

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;

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

  ll n, m, i, j;

  cin >> n >> m;

  string ar[n];

  for (i = 0; i < n; ++i)
    cin >> ar[i];

  ll dp[n + 1][m + 1];

  for (j = 0; j <= m; ++j)
    dp[0][j] = 0;
  for (i = 0; i <= n; ++i)
    dp[i][0] = 0;

  dp[0][1] = 1;

  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      if (ar[i - 1][j - 1] == '.')
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
      else
        dp[i][j] = 0;
    }

  cout << dp[n][m];

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define fastread                                                               \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define print(a)                                                               \
  for (auto x : a)                                                             \
    cout << x << ' ';                                                          \
  cout << endl;
#define printM(b)                                                              \
  for (auto y : b) {                                                           \
    print(y);                                                                  \
  }
#define printP(p) cout << p.first << ' ' << p.second << endl;

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;

int main() {
  fastread;

  ll n, m, i, j;

  cin >> n >> m;

  string ar[n];

  for (i = 0; i < n; ++i)
    cin >> ar[i];

  ll dp[n + 1][m + 1];

  for (j = 0; j <= m; ++j)
    dp[0][j] = 0;
  for (i = 0; i <= n; ++i)
    dp[i][0] = 0;

  dp[0][1] = 1;

  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      if (ar[i - 1][j - 1] == '.')
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % 1000000007;
      else
        dp[i][j] = 0;
    }

  cout << dp[n][m];

  return 0;
}