Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

template <class Type> inline bool chmax(Type &a, Type b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class Type> inline bool chmin(Type &a, Type b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class Type> Type modpow(Type a, Type n, Type mod) {
  Type res = 1;
  while (0 < n) {
    if (n & 1) {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

template <class Type> Type gcd(Type x, Type y) {
  Type r;
  if (x < y) {
    swap(x, y);
  }

  while (0 < y) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

template <class Type> Type lcm(Type x, Type y) { return x * y / gcd(x, y); }

template <class Type> bool isPrime(Type x) {
  if (x == 2)
    return true;
  if (x < 2 || x % 2 == 0)
    return false;

  for (Type i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0)
      return false;
  }
  return true;
}

template <class Type> vector<bool> eratos(Type n) {
  vector<bool> isPrime(n + 1, true);
  isPrime[0] = isPrime[1] = false;
  for (Type i = 2; i <= n; i++) {
    if (isPrime[i]) {
      Type j = i + i;
      while (j <= n) {
        isPrime[j] = false;
        j = j + i;
      }
    }
  }
  return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key) {
  if (key <= a[index])
    return true;
  else
    return false;
}

int binarySearch(vector<int> a, int key) {
  int ng = -1;
  int ok = a.size();
  while (1 < abs(ng - ok)) {
    int mid = (ng + ok) / 2;
    if (binarySearchJudge(a, mid, key))
      ok = mid;
    else
      ng = mid;
  }
  return a[ok] == key;
}

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++)
    cin >> a[i];

  vector<vector<ll>> dp(h, vector<ll>(w));
  for (int j = 1; j < w; j++) {
    if (a[0][j] == '#')
      break;
    else
      dp[0][j] = 1;
  }
  for (int i = 1; i < w; i++) {
    if (a[i][0] == '#')
      break;
    else
      dp[i][0] = 1;
  }

  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (a[i][j] != '#') {
        dp[i][j] += dp[i - 1][j];
        dp[i][j] += dp[i][j - 1];
        dp[i][j] %= mod;
      } else
        dp[i][j] = 0;
    }
  }

  cout << dp[h - 1][w - 1] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;

template <class Type> inline bool chmax(Type &a, Type b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class Type> inline bool chmin(Type &a, Type b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class Type> Type modpow(Type a, Type n, Type mod) {
  Type res = 1;
  while (0 < n) {
    if (n & 1) {
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

template <class Type> Type gcd(Type x, Type y) {
  Type r;
  if (x < y) {
    swap(x, y);
  }

  while (0 < y) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

template <class Type> Type lcm(Type x, Type y) { return x * y / gcd(x, y); }

template <class Type> bool isPrime(Type x) {
  if (x == 2)
    return true;
  if (x < 2 || x % 2 == 0)
    return false;

  for (Type i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0)
      return false;
  }
  return true;
}

template <class Type> vector<bool> eratos(Type n) {
  vector<bool> isPrime(n + 1, true);
  isPrime[0] = isPrime[1] = false;
  for (Type i = 2; i <= n; i++) {
    if (isPrime[i]) {
      Type j = i + i;
      while (j <= n) {
        isPrime[j] = false;
        j = j + i;
      }
    }
  }
  return isPrime;
}

bool binarySearchJudge(vector<int> a, int index, int key) {
  if (key <= a[index])
    return true;
  else
    return false;
}

int binarySearch(vector<int> a, int key) {
  int ng = -1;
  int ok = a.size();
  while (1 < abs(ng - ok)) {
    int mid = (ng + ok) / 2;
    if (binarySearchJudge(a, mid, key))
      ok = mid;
    else
      ng = mid;
  }
  return a[ok] == key;
}

int main() {
  ll h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++)
    cin >> a[i];

  vector<vector<ll>> dp(h, vector<ll>(w));
  for (int j = 1; j < w; j++) {
    if (a[0][j] == '#')
      break;
    else
      dp[0][j] = 1;
  }
  for (int i = 1; i < h; i++) {
    if (a[i][0] == '#')
      break;
    else
      dp[i][0] = 1;
  }

  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (a[i][j] != '#') {
        dp[i][j] += dp[i - 1][j];
        dp[i][j] += dp[i][j - 1];
        dp[i][j] %= mod;
      } else
        dp[i][j] = 0;
    }
  }

  cout << dp[h - 1][w - 1] << endl;
}