Problem p03167 (C++)

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

#include <iostream>
// #include <algorithm>
//  #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

ll dp[105][105];

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll H, W;
  scanf("%lld %lld", &H, &W);

  vector<string> lines;
  for (ll i = 0; i < H; i++) {
    string s;
    cin >> s;

    lines.emplace_back(s);
  }

  dp[0][0] = 1;

  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      if (y + 1 < H && lines[y + 1][x] == '.') {
        dp[y + 1][x] += dp[y][x];
        dp[y + 1][x] %= MOD;
        // cout << y + 1 << " " << x << " " << dp[y + 1][x] << endl;
      }
      if (x + 1 < W && lines[y][x + 1] == '.') {
        dp[y][x + 1] += dp[y][x];
        dp[y][x + 1] %= MOD;
        // cout << y << " " << x + 1 << " " << dp[y][x + 1] << endl;
      }
    }
  }

  /*
    for (;;) {
      pair<ll, ll> c = q.front();
      q.pop();

      cout << c.first << " " << c.second << endl;

      bool can_v = false;
      if (c.first + 1 < H && lines[c.first + 1][c.second] == '.') {
        can_v = true;
      }

      bool can_h = false;
      if (c.second + 1 < W && lines[c.first][c.second + 1] == '.') {
        can_h = true;
      }

      if (can_v && can_h) {
        q.push(make_pair(c.first + 1, c.second));
        q.push(make_pair(c.first, c.second + 1));
        dp[c.first + 1][c.second] = dp[c.first][c.second] + 1;
        dp[c.first][c.second + 1] = dp[c.first][c.second] + 1;
      } else if (can_v) {
        q.push(make_pair(c.first + 1, c.second));
        if (dp[c.first + 1][c.second] == 0) {

        }
        dp[c.first + 1][c.second] = dp[c.first][c.second];
      } else if (can_h) {
        q.push(make_pair(c.first, c.second + 1));
        dp[c.first][c.second + 1] = dp[c.first][c.second];
      }
    }
    */
  cout << dp[H - 1][W - 1] << endl;
}


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

#include <iostream>
// #include <algorithm>
//  #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

ll dp[1005][1005];

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll H, W;
  scanf("%lld %lld", &H, &W);

  vector<string> lines;
  for (ll i = 0; i < H; i++) {
    string s;
    cin >> s;

    lines.emplace_back(s);
  }

  dp[0][0] = 1;

  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      if (y + 1 < H && lines[y + 1][x] == '.') {
        dp[y + 1][x] += dp[y][x];
        dp[y + 1][x] %= MOD;
        // cout << y + 1 << " " << x << " " << dp[y + 1][x] << endl;
      }
      if (x + 1 < W && lines[y][x + 1] == '.') {
        dp[y][x + 1] += dp[y][x];
        dp[y][x + 1] %= MOD;
        // cout << y << " " << x + 1 << " " << dp[y][x + 1] << endl;
      }
    }
  }

  /*
    for (;;) {
      pair<ll, ll> c = q.front();
      q.pop();

      cout << c.first << " " << c.second << endl;

      bool can_v = false;
      if (c.first + 1 < H && lines[c.first + 1][c.second] == '.') {
        can_v = true;
      }

      bool can_h = false;
      if (c.second + 1 < W && lines[c.first][c.second + 1] == '.') {
        can_h = true;
      }

      if (can_v && can_h) {
        q.push(make_pair(c.first + 1, c.second));
        q.push(make_pair(c.first, c.second + 1));
        dp[c.first + 1][c.second] = dp[c.first][c.second] + 1;
        dp[c.first][c.second + 1] = dp[c.first][c.second] + 1;
      } else if (can_v) {
        q.push(make_pair(c.first + 1, c.second));
        if (dp[c.first + 1][c.second] == 0) {

        }
        dp[c.first + 1][c.second] = dp[c.first][c.second];
      } else if (can_h) {
        q.push(make_pair(c.first, c.second + 1));
        dp[c.first][c.second + 1] = dp[c.first][c.second];
      }
    }
    */
  cout << dp[H - 1][W - 1] << endl;
}