Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc)
#define cin(t)                                                                 \
  int t;                                                                       \
  cin >> t
#define w(t) while (t--)
#define nl cout << endl;
#define pb push_back
#define ft(i) (i & (-1 * i))
#define arrIn(arr, size)                                                       \
  for (int i = 0; i < size; i++) {                                             \
    cin >> arr[i];                                                             \
  }
#define arrOut(arr, size, seperater)                                           \
  for (int i = 0; i < size; i++) {                                             \
    cout << arr[i] << seperater;                                               \
  }
using namespace std;

int max(int a, int b) {
  if (a > b)
    return a;
  return b;
}

int min(int a, int b) {
  if (a < b)
    return a;
  return b;
}

void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int h, w;
char grid[1005][1005];

int solve() {
  int dp[h][w];
  fo(i, 0, h, 1) {
    fo(j, 0, w, 1) { dp[i][j] = 0; }
  }
  fo(i, 0, w, 1) {
    if (grid[0][i] == '#')
      break;
    dp[0][i] = 1;
  }
  fo(i, 0, h, 1) {
    if (grid[i][0] == '#')
      break;
    dp[i][0] = 1;
  }

  fo(i, 1, h - 1, 1) {
    fo(j, 1, w - 1, 1) {
      if (grid[i][j] == '#')
        continue;

      dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      dp[i][j] %= mod;
    }
  }

  return dp[h - 1][w - 1] % mod;
}

int32_t main() {

  fastIO();
  cin >> h >> w;

  fo(i, 0, h, 1) {
    fo(j, 0, w, 1) { cin >> grid[i][j]; }
  }

  cout << solve();
  nl;
  return 0;
}

// cout << "Case #" << i << ": " << answer << endl;

Fixed submission:
#include <bits/stdc++.h>
#define int long long int
#define mod 1000000007
#define inf 1e18
#define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc)
#define cin(t)                                                                 \
  int t;                                                                       \
  cin >> t
#define w(t) while (t--)
#define nl cout << endl;
#define pb push_back
#define ft(i) (i & (-1 * i))
#define arrIn(arr, size)                                                       \
  for (int i = 0; i < size; i++) {                                             \
    cin >> arr[i];                                                             \
  }
#define arrOut(arr, size, seperater)                                           \
  for (int i = 0; i < size; i++) {                                             \
    cout << arr[i] << seperater;                                               \
  }
using namespace std;

int max(int a, int b) {
  if (a > b)
    return a;
  return b;
}

int min(int a, int b) {
  if (a < b)
    return a;
  return b;
}

void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int h, w;
char grid[1005][1005];

int solve() {
  int dp[h][w];
  fo(i, 0, h, 1) {
    fo(j, 0, w, 1) { dp[i][j] = 0; }
  }
  fo(i, 0, w, 1) {
    if (grid[0][i] == '#')
      break;
    dp[0][i] = 1;
  }
  fo(i, 0, h, 1) {
    if (grid[i][0] == '#')
      break;
    dp[i][0] = 1;
  }

  fo(i, 1, h - 1, 1) {
    fo(j, 1, w - 1, 1) {
      if (grid[i][j] == '#')
        continue;

      dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      dp[i][j] %= mod;
    }
  }

  return dp[h - 1][w - 1] % mod;
}

int32_t main() {

  cin >> h >> w;

  fo(i, 0, h, 1) {
    fo(j, 0, w, 1) { cin >> grid[i][j]; }
  }

  cout << solve();
  nl;
  return 0;
}

// cout << "Case #" << i << ": " << answer << endl;