prithivMLmods/Coder-Stat huggingface dataset:
Problem p03167 (C++)

Buggy submission (status: Time Limit Exceeded):
// i_am_arin

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;

#define f(i, a, n) for (ll i = a; i < (ll)n; i++)
#define f2(i, a, b) for (ll i = a; i <= (ll)b; i++)
#define PB push_back
#define FF first
#define SS second
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

ll h, w;
vector<string> s(1000);
ll dp[1005][1005];

ll go(ll h, ll w) {
  if (w == 0 && h == 0)
    return 1;
  // if(dp[h][w]!=-1) return dp[h][w];
  if (h == 0) {
    if (s[h][w] == '.')
      return dp[h][w] = go(h, w - 1);
    else
      return dp[h][w] = 0;
  }
  if (w == 0) {
    if (s[h][w] == '.')
      return dp[h][w] = go(h - 1, w);
    else
      return dp[h][w] = 0;
  }
  if (s[h][w] == '.')
    return dp[h][w] = (go(h - 1, w) + go(h, w - 1)) % MOD;
  else
    return dp[h][w] = 0;
}

void solve() {

  cin >> h >> w;

  memset(dp, -1, sizeof(dp));
  f(i, 0, h) cin >> s[i];
  cout << go(h - 1, w - 1) << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Fixed submission:
// i_am_arin

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<long long> vll;
typedef vector<string> vs;

#define f(i, a, n) for (ll i = a; i < (ll)n; i++)
#define f2(i, a, b) for (ll i = a; i <= (ll)b; i++)
#define PB push_back
#define FF first
#define SS second
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

ll h, w;
vector<string> s(1000);
ll dp[1005][1005];

ll go(ll h, ll w) {
  if (w == 0 && h == 0)
    return 1;
  if (dp[h][w] != -1)
    return dp[h][w];
  if (h == 0) {
    if (s[h][w] == '.')
      return dp[h][w] = go(h, w - 1);
    else
      return dp[h][w] = 0;
  }
  if (w == 0) {
    if (s[h][w] == '.')
      return dp[h][w] = go(h - 1, w);
    else
      return dp[h][w] = 0;
  }
  if (s[h][w] == '.')
    return dp[h][w] = (go(h - 1, w) + go(h, w - 1)) % MOD;
  else
    return dp[h][w] = 0;
}

void solve() {

  cin >> h >> w;

  memset(dp, -1, sizeof(dp));
  f(i, 0, h) cin >> s[i];
  cout << go(h - 1, w - 1) << endl;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
// Nguyen Anh Tu
#include <bits/stdc++.h>
#define FOR(x, a, b) for (int x = a; x <= b; x++)
#define FORD(x, a, b) for (int x = a; x >= b; x--)
#define maxn 1005
#define maxc 1000000007
#define MOD 1000000007
#define reset(x, y) memset(x, y, sizeof(x))
#define task ""
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int, int>
#define ll long long
#define bit(p, x) ((x >> p) & 1)
#define remain(a, b) (a + b >= MOD) ? (a + b - MOD) : (a + b)

using namespace std;
int n, m;
ll dp[maxn][maxn];
char a[maxn][maxn];
int main() {
#ifndef ONLINE_JUDGE
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  freopen(task ".inp", "r", stdin);
  freopen(task ".out", "w", stdout);
#endif
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      cin >> a[i][j];
  dp[1][1] = (a[1][1] == '.');
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] == '.') {
        if (a[i - 1][j] == '.')
          (dp[i][j] += dp[i - 1][j]) %= maxc;
        if (a[i][j - 1] == '.')
          (dp[i][j] += dp[i][j - 1]) %= maxc;
      }
  cout << dp[n][m];
}


Fixed submission:
// Nguyen Anh Tu
#include <bits/stdc++.h>
#define FOR(x, a, b) for (int x = a; x <= b; x++)
#define FORD(x, a, b) for (int x = a; x >= b; x--)
#define maxn 1005
#define maxc 1000000007
#define MOD 1000000007
#define reset(x, y) memset(x, y, sizeof(x))
#define task ""
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int, int>
#define ll long long
#define bit(p, x) ((x >> p) & 1)
#define remain(a, b) (a + b >= MOD) ? (a + b - MOD) : (a + b)

using namespace std;
int n, m;
ll dp[maxn][maxn];
char a[maxn][maxn];
int main() {
  //    #ifndef ONLINE_JUDGE
  //    ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
  //    freopen(task".inp","r",stdin);
  //    freopen(task".out","w",stdout);
  //    #endif
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      cin >> a[i][j];
  dp[1][1] = (a[1][1] == '.');
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i][j] == '.') {
        if (a[i - 1][j] == '.')
          (dp[i][j] += dp[i - 1][j]) %= maxc;
        if (a[i][j - 1] == '.')
          (dp[i][j] += dp[i][j - 1]) %= maxc;
      }
  cout << dp[n][m];
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define IOS                                                                    \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;
ll arr[101][101];
int main() {
  IOS;
  int w, h;
  char x;
  ll const num = 1000000007;
  cin >> h >> w;

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> x;

      if (i == 1 && j == 1 && x != '#') {
        arr[i][j] = 1;
      } else if (x == '#')
        arr[i][j] = 0;
      else {
        arr[i][j] = (arr[i - 1][j] % num + arr[i][j - 1] % num) % num;
      }
    }
  }
  cout << arr[h][w];
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define IOS                                                                    \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define F first
#define S second
#define pb push_back
using namespace std;
ll arr[1001][1001];
int main() {
  IOS;
  int w, h;
  char x;
  ll const num = 1000000007;
  cin >> h >> w;

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> x;

      if (i == 1 && j == 1 && x != '#') {
        arr[i][j] = 1;
      } else if (x == '#')
        arr[i][j] = 0;
      else {
        arr[i][j] = (arr[i - 1][j] % num + arr[i][j - 1] % num) % num;
      }
    }
  }
  cout << arr[h][w];
}
Problem p03167 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define print printf("==================\n")
#define ll long long
#define pi acos(-1.0)
#define eps 1e-16
#define max3(a, b, c) max(a, max(b, c))
const ll INF = 1 << 30;
#define mod 1000000007
typedef pair<double, double> payar;
typedef struct {
  ll x, y;
} point;
priority_queue<payar, vector<payar>, greater<payar>> pq; /// accending
vector<pair<double, payar>> vpp;
vector<payar> vp;
char ara[1006][1006];
ll dp[1006][1005];
int n, m;
ll cal(int i, int j) {
  if (i > n or j > m)
    return 0;
  if (i == n and j == m)
    return 1;
  if (ara[i][j] == '#')
    return 0;
  if (dp[i][j] != -1)
    return dp[i][j] % mod;
  return (cal(i + 1, j) % mod + cal(i, j + 1) % mod) % mod;
}
int main() {

  cin >> n >> m;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> ara[i][j];
    }
  }
  cout << cal(1, 1);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define print printf("==================\n")
#define ll long long
#define pi acos(-1.0)
#define eps 1e-16
#define max3(a, b, c) max(a, max(b, c))
const ll INF = 1 << 30;
#define mod 1000000007
typedef pair<double, double> payar;
typedef struct {
  ll x, y;
} point;
priority_queue<payar, vector<payar>, greater<payar>> pq; /// accending
vector<pair<double, payar>> vpp;
vector<payar> vp;
char ara[1006][1006];
ll dp[1006][1005];
int n, m;
ll cal(int i, int j) {
  if (i > n or j > m)
    return 0;
  if (i == n and j == m)
    return 1;
  if (ara[i][j] == '#')
    return 0;
  if (dp[i][j] != -1)
    return dp[i][j] % mod;
  return dp[i][j] = (cal(i + 1, j) % mod + cal(i, j + 1) % mod) % mod;
}
int main() {

  cin >> n >> m;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> ara[i][j];
    }
  }
  cout << cal(1, 1);

  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
// #define large 1050
#define large 100
#define mod 1000000007

int main() {
  int h, w;
  char a[large][large];

  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", &a[i]);
  }

  int dp[large][large] = {};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i == 0 && j == 0) {
        dp[i][j] += 1;
        continue;
      }
      if (a[i][j] == '#')
        continue;
      if (i != 0) {
        dp[i][j] += dp[i - 1][j];
        dp[i][j] %= mod;
      }
      if (j != 0) {
        dp[i][j] += dp[i][j - 1];
        dp[i][j] %= mod;
      }
    }
  }
  // for(int i=0;i<h;i++)
  // {
  //     for(int j=0;j<w;j++)
  //     {
  //         printf("%d ",dp[i][j]);
  //     }
  //     printf("\n");
  // }
  printf("%d\n", dp[h - 1][w - 1]);
}

Fixed submission:
#include <stdio.h>
#define large 1050
// #define large 100
#define mod 1000000007

int main() {
  int h, w;
  char a[large][large];

  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", &a[i]);
  }

  int dp[large][large] = {};
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i == 0 && j == 0) {
        dp[i][j] += 1;
        continue;
      }
      if (a[i][j] == '#')
        continue;
      if (i != 0) {
        dp[i][j] += dp[i - 1][j];
        dp[i][j] %= mod;
      }
      if (j != 0) {
        dp[i][j] += dp[i][j - 1];
        dp[i][j] %= mod;
      }
    }
  }
  // for(int i=0;i<h;i++)
  // {
  //     for(int j=0;j<w;j++)
  //     {
  //         printf("%d ",dp[i][j]);
  //     }
  //     printf("\n");
  // }
  printf("%d\n", dp[h - 1][w - 1]);
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int height, width;
long long int dp[1010][1010];
string a[1000];
int main() {
  ios::sync_with_stdio(false);
  cin >> height >> width;
  for (int i = 0; i < height; i++)
    cin >> a[i];
  dp[0][0] = 1;
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      if (a[i][j] == '#')
        continue;
      if (a[i][j + 1] == '.') {
        dp[i][j + 1] += dp[i][j];
        dp[i][j + 1] %= 1000000007;
      }
      if (a[i + 1][j] == '.') {
        dp[i + 1][j] += dp[i][j];
        dp[i + 1][j] %= 1000000007;
      }
    }
  }
  cout << dp[height - 1][width - 1] % (1000000007) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int height, width;
long long int dp[1010][1010];
string a[1001];
int main() {
  ios::sync_with_stdio(false);
  cin >> height >> width;
  for (int i = 0; i < height; i++)
    cin >> a[i];
  dp[0][0] = 1;
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      if (a[i][j] == '#')
        continue;
      if (a[i][j + 1] == '.') {
        dp[i][j + 1] += dp[i][j];
        dp[i][j + 1] %= 1000000007;
      }
      if (a[i + 1][j] == '.') {
        dp[i + 1][j] += dp[i][j];
        dp[i + 1][j] %= 1000000007;
      }
    }
  }
  cout << dp[height - 1][width - 1] % (1000000007) << endl;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> grid(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  vector<vector<int>> dp(n, vector<int>(m, 0));
  dp[0][0] = 1;
  for (int i = 1; i < m; i++) {
    if (grid[0][i] == '#')
      break;
    dp[0][i] = dp[0][i - 1] % 1000000007;
  }
  for (int i = 1; i < m; i++) {
    if (grid[i][0] == '#')
      break;
    dp[i][0] = dp[i - 1][0] % 1000000007;
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (grid[i][j] == '#')
        continue;
      if (grid[i - 1][j] != '#')
        dp[i][j] = (dp[i][j] % mod + dp[i - 1][j] % mod) % mod;
      if (grid[i][j - 1] != '#')
        dp[i][j] = (dp[i][j] % mod + dp[i][j - 1] % mod) % mod;
    }
  }
  cout << dp[n - 1][m - 1];
}

Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> grid(n, vector<char>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  vector<vector<int>> dp(n, vector<int>(m, 0));
  dp[0][0] = 1;
  for (int i = 1; i < m; i++) {
    if (grid[0][i] == '#')
      break;
    dp[0][i] = dp[0][i - 1] % 1000000007;
  }
  for (int i = 1; i < n; i++) {
    if (grid[i][0] == '#')
      break;
    dp[i][0] = dp[i - 1][0] % 1000000007;
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (grid[i][j] == '#')
        continue;
      if (grid[i - 1][j] != '#')
        dp[i][j] = (dp[i][j] % mod + dp[i - 1][j] % mod) % mod;
      if (grid[i][j - 1] != '#')
        dp[i][j] = (dp[i][j] % mod + dp[i][j - 1] % mod) % mod;
    }
  }
  cout << dp[n - 1][m - 1];
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1e9 + 7;

void solve() {
  int h, w;
  cin >> h >> w;
  vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      if (c == '#') {
        dp[i + 1][j + 1] = -1;
      }
    }
  }
  dp[0][1] = 1;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (dp[i][j] < 0) {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD;
    }
  }
  cout << dp[h][w];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1e9 + 7;

void solve() {
  int h, w;
  cin >> h >> w;
  vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      if (c == '#') {
        dp[i + 1][j + 1] = -1;
      }
    }
  }
  dp[0][1] = 1;
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      if (dp[i][j] < 0) {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD;
    }
  }
  cout << dp[h][w];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  // #endif
  solve();
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 100 + 10
#define ll long long int

using namespace std;
int main() {
  int h, w, current, last;
  ll table[2][N];
  string map;

  cin >> h >> w;

  // initial conditions
  for (int i = 0; i <= w; i++) {
    table[0][i] = 0;
    table[1][i] = 0;
  }
  table[0][1] = 1LL;

  for (int i = 1; i <= h; i++) {
    current = i % 2;
    last = (i + 1) % 2;
    cin >> map;
    for (int j = 1; j <= w; j++) {
      table[current][j] = 0;
      if (map[j - 1] != '#') {
        table[current][j] =
            (table[last][j] + table[current][j - 1]) % ((long long)1e9 + 7);
      }
    }
  }

  cout << table[h % 2][w] << '\n';
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define N 1000 + 10
#define ll long long int

using namespace std;
int main() {
  int h, w, current, last;
  ll table[2][N];
  string map;

  cin >> h >> w;

  // initial conditions
  for (int i = 0; i <= w; i++) {
    table[0][i] = 0;
    table[1][i] = 0;
  }
  table[0][1] = 1LL;

  for (int i = 1; i <= h; i++) {
    current = i % 2;
    last = (i + 1) % 2;
    cin >> map;
    for (int j = 1; j <= w; j++) {
      table[current][j] = 0;
      if (map[j - 1] != '#') {
        table[current][j] =
            (table[last][j] + table[current][j - 1]) % ((long long)1e9 + 7);
      }
    }
  }

  cout << table[h % 2][w] << '\n';
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ROCK                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define f first
#define sec second
using namespace std;
typedef long long ll;
const long long int linf = (ll)9e18;
const int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1},
          dy[8] = {1, -1, 0, 0, 1, -1, -1, 1};

const int N = 105, MOD = (int)1e9 + 7;
ll n, m, dp[N][N];
char grid[N][N];

bool isvalid(int i, int j) {
  return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] != '#';
}

ll solve(int i, int j) {
  if (i == n - 1 && j == m - 1)
    return 1;
  ll &ret = dp[i][j];
  if (~ret)
    return ret;
  ll right = 0;
  if (isvalid(i + 1, j))
    right = solve(i + 1, j);
  ll down = 0;
  if (isvalid(i, j + 1))
    down = solve(i, j + 1);
  return ret = (right % MOD + down % MOD) % MOD;
}

int main() {
  ROCK;
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> grid[i][j];
  cout << solve(0, 0) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ROCK                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define f first
#define sec second
using namespace std;
typedef long long ll;
const long long int linf = (ll)9e18;
const int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1},
          dy[8] = {1, -1, 0, 0, 1, -1, -1, 1};

const int N = 1005, MOD = (int)1e9 + 7;
ll n, m, dp[N][N];
char grid[N][N];

bool isvalid(int i, int j) {
  return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] != '#';
}

ll solve(int i, int j) {
  if (i == n - 1 && j == m - 1)
    return 1;
  ll &ret = dp[i][j];
  if (~ret)
    return ret;
  ll right = 0;
  if (isvalid(i + 1, j))
    right = solve(i + 1, j);
  ll down = 0;
  if (isvalid(i, j + 1))
    down = solve(i, j + 1);
  return ret = (right % MOD + down % MOD) % MOD;
}

int main() {
  ROCK;
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> grid[i][j];
  cout << solve(0, 0) << endl;
  return 0;
}
Problem p03167 (C++)

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

char grid[105][105];
long long int mem[105][105];

long long int n, m;

long long int dp(long long int i, long long int j) {
  if (i == n - 1 && j == m - 1) {
    return 1;
  }
  if (mem[i][j] != -1) {
    return mem[i][j];
  }
  long long int x = 0;
  if (i + 1 < n && grid[i + 1][j] == '.') {
    x = (x + dp(i + 1, j)) % 1000000007;
  }
  if (j + 1 < m && grid[i][j + 1] == '.')
    x = (x + dp(i, j + 1)) % 1000000007;
  mem[i][j] = x;
  // cout<<"i: "<<i<<" j: "<<j<<" = "<<x<<endl;
  return x;
}

int main() {

  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  memset(mem, -1, sizeof(mem));
  long long int ans = dp(0, 0) % 1000000007;
  cout << ans;
  return 0;
}

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

char grid[1005][1005];
long long int mem[1005][1005];

long long int n, m;

long long int dp(long long int i, long long int j) {
  if (i == n - 1 && j == m - 1) {
    return 1;
  }
  if (mem[i][j] != -1) {
    return mem[i][j];
  }
  long long int x = 0;
  if (i + 1 < n && grid[i + 1][j] == '.') {
    x = (x + dp(i + 1, j)) % 1000000007;
  }
  if (j + 1 < m && grid[i][j + 1] == '.')
    x = (x + dp(i, j + 1)) % 1000000007;
  mem[i][j] = x;
  // cout<<"i: "<<i<<" j: "<<j<<" = "<<x<<endl;
  return x;
}

int main() {

  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> grid[i][j];
    }
  }
  memset(mem, -1, sizeof(mem));
  long long int ans = dp(0, 0) % 1000000007;
  cout << ans;
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
const int INF = 1e9 + 7;
char a[maxn][maxn];
int dp[maxn][maxn]; // dp[i][j]´ú±íÖÕµãÎªi,jµÄ·½°¸Êý
bool vis[maxn][maxn];
long long ans = 0, h, w;

int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    scanf("%s", a[i] + 1);
  }
  for (int i = 1; i <= w; i++) {
    if (a[1][i] == '.')
      dp[1][i] = 1;
    else
      break;
  }
  for (int i = 1; i <= h; i++) {
    if (a[i][1] == '.')
      dp[i][1] = 1;
    else
      break;
  }

  for (int i = 2; i <= h; i++) {
    for (int j = 2; j <= w; j++) {
      if (a[i][j] == '.') {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % INF;
      }
    }
  }
  cout << dp[h][w];
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1100;
const int INF = 1e9 + 7;
char a[maxn][maxn];
int dp[maxn][maxn]; // dp[i][j]´ú±íÖÕµãÎªi,jµÄ·½°¸Êý
bool vis[maxn][maxn];
long long ans = 0, h, w;

int main() {
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    scanf("%s", a[i] + 1);
  }
  for (int i = 1; i <= w; i++) {
    if (a[1][i] == '.')
      dp[1][i] = 1;
    else
      break;
  }
  for (int i = 1; i <= h; i++) {
    if (a[i][1] == '.')
      dp[i][1] = 1;
    else
      break;
  }

  for (int i = 2; i <= h; i++) {
    for (int j = 2; j <= w; j++) {
      if (a[i][j] == '.') {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % INF;
      }
    }
  }
  cout << dp[h][w];
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 1000000007
string mat[1000];
vector<vector<int>> dp(1000, vector<int>(1000, -1));
int n, x, y, m;
int solve(int i, int j) {
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  if ((i == n - 1 && j == m - 1)) {
    return 1;
  }
  if (i >= n || j >= m || mat[i][j] == '#') {
    return 0;
  }
  dp[i][j] = (solve(i + 1, j) + solve(i, j + 1)) % N;
  return dp[i][j] % N;
}

int main() {
  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    cin >> mat[i];
  }
  cout << solve(0, 0);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 1000000007
string mat[1001];
vector<vector<int>> dp(1001, vector<int>(1001, -1));
int n, x, y, m;
int solve(int i, int j) {
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  if ((i == n - 1 && j == m - 1)) {
    return 1;
  }
  if (i >= n || j >= m || mat[i][j] == '#') {
    return 0;
  }
  dp[i][j] = (solve(i + 1, j) + solve(i, j + 1)) % N;
  return dp[i][j] % N;
}

int main() {
  cin >> n >> m;

  for (int i = 0; i < n; i++) {
    cin >> mat[i];
  }
  cout << solve(0, 0);
}
Problem p03167 (C++)

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) { return b; };
template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); }
template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); }
template <typename T> void chmax(T &x, T y) {
  if (x < y)
    x = y;
}
template <typename T> void chmin(T &x, T y) {
  if (x > y)
    x = y;
}

const long long MOD = 1000000007;
const int MAX_HW = 1000;
int h, w;
string grid[MAX_HW];
ll c[MAX_HW][MAX_HW];
int dx[2] = {1, 0};
int dy[2] = {0, 1};

ll dfs(int i, int j) {
  if (c[i][j] >= 0)
    return c[i][j];

  if (i == h - 1 && j == w - 1)
    return c[i][j] = 1;

  ll res = 0;

  forn(k, 2) {
    int x = i + dx[k], y = j + dy[k];
    if (grid[x][y] == '.')
      res = (res + dfs(x, y)) % MOD;
  }

  return c[i][j] = res;
}

int main() {
#ifdef FASTIO
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif

  cin >> h >> w;
  forn(i, h) cin >> grid[i];

  forn(i, h) fill_n(c[i], w, -1);

  cout << dfs(0, 0) << endl;

  return 0;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) { return b; };
template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); }
template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); }
template <typename T> void chmax(T &x, T y) {
  if (x < y)
    x = y;
}
template <typename T> void chmin(T &x, T y) {
  if (x > y)
    x = y;
}

const long long MOD = 1000000007;
const int MAX_HW = 1000;
int h, w;
string grid[MAX_HW];
ll c[MAX_HW][MAX_HW];
int dx[2] = {1, 0};
int dy[2] = {0, 1};

ll dfs(int i, int j) {
  if (c[i][j] >= 0)
    return c[i][j];

  if (i == h - 1 && j == w - 1)
    return c[i][j] = 1;

  ll res = 0;

  forn(k, 2) {
    int x = i + dx[k], y = j + dy[k];
    if (x < h && y < w && grid[x][y] == '.')
      res = (res + dfs(x, y)) % MOD;
  }

  return c[i][j] = res;
}

int main() {
#ifdef FASTIO
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif

  cin >> h >> w;
  forn(i, h) cin >> grid[i];

  forn(i, h) fill_n(c[i], w, -1);

  cout << dfs(0, 0) << endl;

  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

ll mod = 1e9 + 7;

int main() {
  fast();
  ll r, c;
  cin >> r >> c;

  ll dp[r][c];
  char arr[r][c];

  for (ll i = 0; i < r; i++) {
    for (ll j = 0; j < c; j++)
      cin >> arr[i][j];
  }

  for (ll i = 0; i <= r; i++) {
    for (ll j = 0; j < c; j++) {
      dp[i][j] = 0;
    }
  }

  dp[r - 1][c - 1] = 1;

  for (ll i = r - 2; i >= 0; i--) {
    if (arr[i][c - 1] == '#')
      dp[i][c - 1] = 0;
    else
      dp[i][c - 1] = dp[i + 1][c - 1];
  }

  for (ll i = c - 2; i >= 0; i--) {
    if (arr[r - 1][i] == '#')
      dp[r - 1][i] = 0;
    else
      dp[r - 1][i] = dp[r - 1][i + 1];
  }

  for (ll i = r - 2; i >= 0; i--) {
    for (ll j = c - 2; j >= 0; j--) {

      if (arr[i][j] == '#') {
        dp[i][j] = 0;
      } else {
        dp[i][j] = (dp[i][j + 1] + dp[i + 1][j]) % mod;
      }
    }
  }

  cout << dp[0][0];
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

ll mod = 1e9 + 7;

int main() {
  fast();
  ll r, c;
  cin >> r >> c;

  ll dp[r][c];
  char arr[r][c];

  for (ll i = 0; i < r; i++) {
    for (ll j = 0; j < c; j++)
      cin >> arr[i][j];
  }

  for (ll i = 0; i < r; i++) {
    for (ll j = 0; j < c; j++) {
      dp[i][j] = 0;
    }
  }

  dp[r - 1][c - 1] = 1;

  for (ll i = r - 2; i >= 0; i--) {
    if (arr[i][c - 1] == '#')
      dp[i][c - 1] = 0;
    else
      dp[i][c - 1] = dp[i + 1][c - 1];
  }

  for (ll i = c - 2; i >= 0; i--) {
    if (arr[r - 1][i] == '#')
      dp[r - 1][i] = 0;
    else
      dp[r - 1][i] = dp[r - 1][i + 1];
  }

  for (ll i = r - 2; i >= 0; i--) {
    for (ll j = c - 2; j >= 0; j--) {

      if (arr[i][j] == '#') {
        dp[i][j] = 0;
      } else {
        dp[i][j] = (dp[i][j + 1] + dp[i + 1][j]) % mod;
      }
    }
  }

  cout << dp[0][0];
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define m 1000000007
int main() {
  ll i, j, a[10000][10000], dp[10000][10000] = {0}, h, w;
  char ch;
  cin >> h >> w;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cin >> ch;
      if (ch == '.')
        a[i][j] = 1;
      else
        a[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for (j = 1; j < w; j++) {
    if (a[0][j] == 1)
      dp[0][j] += dp[0][j - 1];
  }
  for (i = 1; i < h; i++) {
    if (a[i][0] == 1)
      dp[i][0] += dp[i - 1][0];
  }
  for (i = 1; i < h; i++) {
    for (j = 1; j < w; j++) {
      if (a[i][j - 1] == 1)
        dp[i][j] += dp[i][j - 1];
      if (a[i - 1][j] == 1)
        dp[i][j] += dp[i - 1][j];
      dp[i][j] %= m;
    }
  }
  cout << dp[h - 1][w - 1];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define m 1000000007
int main() {
  ll i, j, a[1001][1001], dp[1001][1001] = {0}, h, w;
  char ch;
  cin >> h >> w;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cin >> ch;
      if (ch == '.')
        a[i][j] = 1;
      else
        a[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for (j = 1; j < w; j++) {
    if (a[0][j] == 1)
      dp[0][j] += dp[0][j - 1];
  }
  for (i = 1; i < h; i++) {
    if (a[i][0] == 1)
      dp[i][0] += dp[i - 1][0];
  }
  for (i = 1; i < h; i++) {
    for (j = 1; j < w; j++) {
      if (a[i][j - 1] == 1)
        dp[i][j] += dp[i][j - 1];
      if (a[i - 1][j] == 1)
        dp[i][j] += dp[i - 1][j];
      dp[i][j] %= m;
    }
  }
  cout << dp[h - 1][w - 1];
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N = 1005;
const int MOD = 1e9 + 7;

int n, m;
char a[N][N];
int cache[N][N];

int dp(int i, int j) {
  if (i > n || j > m)
    return 0;
  if (a[i][j] == '#')
    return 0;
  if (i == n && j == m)
    return 1;
  int &ans = cache[i][j];
  if (ans != -1)
    return ans;
  ans = dp(i + 1, j) + dp(i, j + 1);
  ans %= MOD;
  return ans;
}

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(cache, -1, sizeof(cache));
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      cin >> a[i][j];
  int ans = dp(1, 1);
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N = 1005;
const int MOD = 1e9 + 7;

int n, m;
char a[N][N];
int cache[N][N];

int dp(int i, int j) {
  if (i > n || j > m)
    return 0;
  if (a[i][j] == '#')
    return 0;
  if (i == n && j == m)
    return 1;
  int &ans = cache[i][j];
  if (ans != -1)
    return ans;
  ans = dp(i + 1, j) + dp(i, j + 1);
  ans %= MOD;
  return ans;
}

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(cache, -1, sizeof(cache));
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      cin >> a[i][j];
  int ans = dp(1, 1);
  cout << ans;
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
// #pragma GCC optimize ("-O3")
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MOD = 1000000007;

ll dp[1010][1010];

void _main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i, 0, H) cin >> a[i];

  dp[0][0] = 1;
  rep(i, 0, H) rep(j, 0, W) {
    if (a[i][j] == '#')
      continue;
    if (a[i][j + 1] == '.')
      dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % MOD;
    if (a[i + 1][j] == '.')
      dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
  }
  cout << dp[H - 1][W - 1] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
// #pragma GCC optimize ("-O3")
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int MOD = 1000000007;

ll dp[1010][1010];

void _main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i, 0, H) cin >> a[i];

  dp[0][0] = 1;
  rep(i, 0, H) rep(j, 0, W) {
    if (a[i][j] == '#')
      continue;
    if (j + 1 < W)
      if (a[i][j + 1] == '.')
        dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % MOD;
    if (i + 1 < H)
      if (a[i + 1][j] == '.')
        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
  }
  cout << dp[H - 1][W - 1] << endl;
}
Problem p03167 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <vector>
#define int long long
#define pi pair<int, int>
#define endl "\n"
using namespace std;

const int inf = 1e15;
const int size = 1e3 + 5;
const int mod = 1e9 + 7;
int dp[size][size];
char a[size][size];

int add(int b, int c) {
  if (b + c >= mod)
    return b + c - mod;
  else
    return b + c;
}

int32_t main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int h, w;
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
    }
  }
  dp[1][0] = 1;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (a[i][j] != '#')
        dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
      // cout<<dp[i][j]<<" ";
    } // cout<<endl;
  }
  cout << dp[h][w] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <vector>
#define int long long
#define pi pair<int, int>
#define endl "\n"
using namespace std;

const int inf = 1e15;
const int size = 1e3 + 5;
const int mod = 1e9 + 7;
int dp[size][size];
char a[size][size];

int add(int b, int c) {
  if (b + c >= mod)
    return b + c - mod;
  else
    return b + c;
}

int32_t main() {

  /*  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
  int h, w;
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
    }
  }
  dp[1][0] = 1;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (a[i][j] != '#')
        dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
      // cout<<dp[i][j]<<" ";
    } // cout<<endl;
  }
  cout << dp[h][w] << endl;
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define fast                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
using namespace std;
const int mod = (int)1e9 + 7;
ll dp[1000][1000];
int main() {
  fast int h, w;
  cin >> h >> w;
  vector<string> s(h + 1);
  for (int i = 1; i <= h; i++)
    cin >> s[i];
  dp[1][1] = 1;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (s[i][j - 1] == '#' || (i == 1 && j == 1))
        continue;
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
    }
  }
  cout << dp[h][w];
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define fast                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
using namespace std;
const int mod = (int)1e9 + 7;
ll dp[1005][1005];
int main() {
  fast int h, w;
  cin >> h >> w;
  vector<string> s(h + 1);
  for (int i = 1; i <= h; i++)
    cin >> s[i];
  dp[1][1] = 1;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (s[i][j - 1] == '#' || (i == 1 && j == 1))
        continue;
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
    }
  }
  cout << dp[h][w];
  return 0;
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#define faster                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
using namespace std;
int MOD = 1e9 + 7;
char ar[1001][1001];
int a[1001][1001] = {-1};

long long find(int i, int j, int h, int w) {
  if (a[i][j] != -1)
    return a[i][j];
  if (ar[i][j] == '#')
    a[i][j] = 0;
  else if (i == h && j == w)
    a[i][j] = 1;
  else if (i == h)
    a[i][j] = find(i, j + 1, h, w);
  else if (j == w)
    a[i][j] = find(i + 1, j, h, w);
  else
    a[i][j] = (find(i + 1, j, h, w) + find(i, j + 1, h, w)) % MOD;
  return a[i][j];
}
signed main() {
  faster;
#ifndef ONLINE_JUDGE
  freopen("ip.txt", "r", stdin);
  freopen("op.txt", "w", stdout);
#endif
  // int t;cin>>t;
  // while(t--)
  {

    int h, w;
    cin >> h >> w;
    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= w; j++)
        cin >> ar[i][j], a[i][j] = -1;
    cout << find(1, 1, h, w) << endl;
    // cout<<a[4][5]<<endl;
  }
}

Fixed submission:
#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#define faster                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
using namespace std;
int MOD = 1e9 + 7;
char ar[1001][1001];
int a[1001][1001] = {-1};

long long find(int i, int j, int h, int w) {
  if (a[i][j] != -1)
    return a[i][j];
  if (ar[i][j] == '#')
    a[i][j] = 0;
  else if (i == h && j == w)
    a[i][j] = 1;
  else if (i == h)
    a[i][j] = find(i, j + 1, h, w);
  else if (j == w)
    a[i][j] = find(i + 1, j, h, w);
  else
    a[i][j] = (find(i + 1, j, h, w) + find(i, j + 1, h, w)) % MOD;
  return a[i][j];
}
signed main() {
  faster;
  // #ifndef ONLINE_JUDGE
  // freopen("ip.txt", "r", stdin);
  // freopen("op.txt", "w", stdout);
  // #endif
  // int t;cin>>t;
  // while(t--)
  {

    int h, w;
    cin >> h >> w;
    for (int i = 1; i <= h; i++)
      for (int j = 1; j <= w; j++)
        cin >> ar[i][j], a[i][j] = -1;
    cout << find(1, 1, h, w) << endl;
    // cout<<a[4][5]<<endl;
  }
}
Problem p03167 (C++)

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

const int INF = 1145141919;
const long long INFL = 1LL << 60;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int H, W;
int a[1100][1100];
long long int memo[1100][1100];

int rec(int x, int y) {
  if (x == 0 || x > W || y == 0 || y > H || a[y][x]) {
    return 0;
  }
  if (memo[y][x] != 0) {
    return memo[y][x];
  }
  // cout << x << " " << y << endl;
  if (x == W && y == H) {
    return 1;
  }
  int ans = 0;
  ans = rec(x + 1, y) + rec(x, y + 1);
  return memo[y][x] = ans % 1000000007;
}

int main() {
  cin >> H >> W;
  char in;
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      cin >> in;
      a[i][j] = (in == '.' ? 0 : 1);
    }
  }
  cout << rec(1, 1) << endl;
  return 0;
}

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

const int INF = 1145141919;
const long long INFL = 1LL << 60;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int H, W;
int a[1100][1100];
long long int memo[1100][1100];

int rec(int x, int y) {
  if (x == 0 || x > W || y == 0 || y > H || a[y][x]) {
    return 0;
  }
  if (memo[y][x] != 0) {
    return memo[y][x];
  }
  // cout << x << " " << y << endl;
  if (x == W && y == H) {
    return 1;
  }
  int ans = 0;
  ans = rec(x + 1, y) + rec(x, y + 1);
  return memo[y][x] = ans % 1000000007;
}

int main() {
  cin >> H >> W;
  char in;
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      cin >> in;
      a[i][j] = (in == '.' ? 0 : 1);
    }
  }
  memo[H][W] = 1;
  for (int i = H; i > 0; --i) {
    for (int j = W; j > 0; --j) {
      if (!a[i][j]) {
        memo[i][j] += memo[i + 1][j] + memo[i][j + 1];
        memo[i][j] %= 1000000007;
      }
    }
  }
  cout << memo[1][1] << endl;
  return 0;
}
Problem p03167 (C++)

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

const int maxn = 110, mod = 1000000007;
int dp[maxn][maxn];
char a[maxn][maxn];

int main() {
  // freopen("demo.in", "r", stdin);
  // freopen("demo.out", "w", stdout);

  int h, w;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", a[i]);
  }
  dp[0][0] = 1;
  for (int i = 1; i < w; i++)
    if (a[0][i] == '.')
      dp[0][i] = dp[0][i - 1];
  for (int i = 1; i < h; i++)
    if (a[i][0] == '.')
      dp[i][0] = dp[i - 1][0];

  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] % mod + dp[i][j - 1] % mod) % mod;
      } else {
        dp[i][j] = 0;
      }
  //	for (int i = 0; i < h; i++) {
  //		for (int j = 0; j < w; j++)
  //			printf("%d ", dp[i][j]);
  //		printf("\n");
  //	}
  printf("%d\n", dp[h - 1][w - 1]);

  return 0;
}


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

const int maxn = 1010, mod = 1000000007;
int dp[maxn][maxn];
char a[maxn][maxn];

int main() {
  // freopen("demo.in", "r", stdin);
  // freopen("demo.out", "w", stdout);

  int h, w;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    scanf("%s", a[i]);
  }
  dp[0][0] = 1;
  for (int i = 1; i < w; i++)
    if (a[0][i] == '.')
      dp[0][i] = dp[0][i - 1];
  for (int i = 1; i < h; i++)
    if (a[i][0] == '.')
      dp[i][0] = dp[i - 1][0];

  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] % mod + dp[i][j - 1] % mod) % mod;
      } else {
        dp[i][j] = 0;
      }
  //	for (int i = 0; i < h; i++) {
  //		for (int j = 0; j < w; j++)
  //			printf("%d ", dp[i][j]);
  //		printf("\n");
  //	}
  printf("%d\n", dp[h - 1][w - 1]);

  return 0;
}
Problem p03167 (C++)

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

using namespace std;

const long long MOD = 1e9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  string arr[h];
  for (int i = 0; i < h; i++)
    cin >> arr[i];
  long long res[h][w];
  res[0][0] = 1LL;
  for (int i = 0; i < w; i++) {
    for (int j = 0; j < h; j++) {
      if (arr[i][j] == '#') {
        res[i][j] = 0;
        continue;
      }
      if (i == 0 && j == 0)
        continue;
      long long a = 0, b = 0;
      if (j >= 1)
        a = res[i][j - 1];
      if (i >= 1)
        b = res[i - 1][j];
      res[i][j] = (a + b) % MOD;
    }
  }
  cout << res[h - 1][w - 1];
}


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

using namespace std;

const long long MOD = 1e9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  string arr[h];
  for (int i = 0; i < h; i++)
    cin >> arr[i];
  long long res[h][w];
  res[0][0] = 1LL;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (arr[i][j] == '#') {
        res[i][j] = 0;
        continue;
      }
      if (i == 0 && j == 0)
        continue;
      long long a = 0, b = 0;
      if (j >= 1)
        a = res[i][j - 1];
      if (i >= 1)
        b = res[i - 1][j];
      res[i][j] = (a + b) % MOD;
    }
  }
  cout << res[h - 1][w - 1];
}
Problem p03167 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
// ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll h, w;
vector<string> a;

ll dp[1100][1100];

void add(ll &a, ll b) {
  a += b;
  if (a >= mod)
    a -= mod;
}

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

  dp[0][0] = 1;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i + 1 < h && a[i + 1][j] == '.')
        add(dp[i + 1][j], dp[i][j]);
      if (j + 1 < w && a[i][j + 1] == '.')
        add(dp[i][j + 1], dp[i][j]);
    }
  }

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

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
// ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;
const ll inf = 1LL << 60;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

ll h, w;
vector<string> a;

ll dp[1100][1100];

void add(ll &a, ll b) {
  a += b;
  if (a >= mod)
    a -= mod;
}

int main() {
  cin >> h >> w;
  a.resize(h);
  for (int i = 0; i < h; i++)
    cin >> a[i];

  dp[0][0] = 1;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i + 1 < h && a[i + 1][j] == '.')
        add(dp[i + 1][j], dp[i][j]);
      if (j + 1 < w && a[i][j + 1] == '.')
        add(dp[i][j + 1], dp[i][j]);
    }
  }

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