Problem p03167 (C++)

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<string, int> msi;
typedef set<ll> sl;
typedef set<char> sc;
typedef pair<int, int> pii;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const int INF = 1 << 29;
#define MOD (ll)(1e9 + 7)
#define eps 1e-6
#define pb push_back
#define mp make_pair
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define F first
#define S second

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

  int n, m;
  cin >> n >> m;
  string a[n];
  REP(i, n) cin >> a[i];

  long long dp[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j)
      dp[i][j] = 0;
  }
  int curr = 1;
  for (int i = 0; i < n; ++i) {
    if (a[i][0] == '#') {
      curr = 0;
    }
    dp[i][0] = curr;
  }
  curr = 1;
  for (int i = 0; i < m; ++i) {
    if (a[0][i] == '#') {
      curr = 0;
    }
    dp[0][i] = curr;
  }

  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      if (a[i][j] == '#') {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      dp[i][j] %= MOD;
    }
  }

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

  cout << dp[n - 1][m - 1] << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef set<int> si;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef map<string, int> msi;
typedef set<ll> sl;
typedef set<char> sc;
typedef pair<int, int> pii;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const int INF = 1 << 29;
#define MOD (ll)(1e9 + 7)
#define eps 1e-6
#define pb push_back
#define mp make_pair
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define F first
#define S second

int main() {
  ios::sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  string a[n];
  REP(i, n) cin >> a[i];

  long long dp[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j)
      dp[i][j] = 0;
  }
  int curr = 1;
  for (int i = 0; i < n; ++i) {
    if (a[i][0] == '#') {
      curr = 0;
    }
    dp[i][0] = curr;
  }
  curr = 1;
  for (int i = 0; i < m; ++i) {
    if (a[0][i] == '#') {
      curr = 0;
    }
    dp[0][i] = curr;
  }

  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      if (a[i][j] == '#') {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      dp[i][j] %= MOD;
    }
  }

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

  cout << dp[n - 1][m - 1] << endl;

  return 0;
}