Problem p03167 (C++)

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

#define fo(i, n) for (ll i = 0; i < n; i++)
#define endl "\n"
#define of(i, n) for (ll i = n - 1; i >= 0; i--)
#define ll long long
#define vec vector<ll>
#define fio                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define tr(container, it)                                                      \
  for (typeof(container.begin()) it = container.begin();                       \
       it != container.end(); it++)

ll mod = 1e9 + 7;

#define umap unordered_map

string sp, tp;

/*string st(string s, string t)
{
    ll n = s.length();
    ll m = t.length();
    if(s.length()==0 || t.length()==0) {dp[n][m]=0;return "";}
    if(dp[s.length()][t.length()]!=0) return  st(s,t);
    else if(s[0]==t[0])
    {
        dp[n][m]++;
        s.erase(s.begin());
        t.erase(t.begin());
        return st(s,t);
    }
}*/

ll ncr(ll n, ll r) {
  long long p = 1, k = 1;
  if (n - r < r)
    r = n - r;

  if (r != 0) {
    while (r) {
      p *= n;
      k *= r;
      long long m = __gcd(p, k);
      p /= m;
      k /= m;

      n--;
      r--;
    }
  }

  else
    p = 1;
  return p;
}
ll dp[1001][1001];
int main() {
  fio;
  ll n, m;
  cin >> n >> m;
  char c[n][m];
  fo(i, n) {
    fo(j, m) { cin >> c[i + 1][j + 1]; }
  }
  ll sum = 0;
  dp[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == '.')
        dp[i][j] += dp[i][j - 1] + dp[i - 1][j];
      dp[i][j] = dp[i][j] % mod;
    }
  }
  cout << dp[n][m];
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define fo(i, n) for (ll i = 0; i < n; i++)
#define endl "\n"
#define of(i, n) for (ll i = n - 1; i >= 0; i--)
#define ll long long
#define vec vector<ll>
#define fio                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define tr(container, it)                                                      \
  for (typeof(container.begin()) it = container.begin();                       \
       it != container.end(); it++)

ll mod = 1e9 + 7;

#define umap unordered_map

string sp, tp;

/*string st(string s, string t)
{
    ll n = s.length();
    ll m = t.length();
    if(s.length()==0 || t.length()==0) {dp[n][m]=0;return "";}
    if(dp[s.length()][t.length()]!=0) return  st(s,t);
    else if(s[0]==t[0])
    {
        dp[n][m]++;
        s.erase(s.begin());
        t.erase(t.begin());
        return st(s,t);
    }
}*/

ll ncr(ll n, ll r) {
  long long p = 1, k = 1;
  if (n - r < r)
    r = n - r;

  if (r != 0) {
    while (r) {
      p *= n;
      k *= r;
      long long m = __gcd(p, k);
      p /= m;
      k /= m;

      n--;
      r--;
    }
  }

  else
    p = 1;
  return p;
}
ll dp[1001][1001];
int main() {
  fio;
  ll n, m;
  cin >> n >> m;
  char c[n + 1][m + 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      cin >> c[i][j];
  }
  ll sum = 0;
  dp[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (c[i][j] == '.')
        dp[i][j] += dp[i][j - 1] + dp[i - 1][j];
      dp[i][j] = dp[i][j] % mod;
    }
  }
  cout << dp[n][m];
}