alexjercan/bugnet huggingface dataset:
Problem p01769 (C++) — buggy submission, verdict: Runtime Error

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

int dp[5010][5010], mod = 1e9 + 7;
int main(int argc, char *argv[]) {
  int n, l;
  cin >> n >> l;
  int x[n], a[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  memset(dp, 0, sizeof(dp));
  dp[0][x[0]] = 1;
  for (int i = x[0] + 1; i < l; i++) {
    if (a[0] == 0) {
      dp[0][i] = dp[0][i - 1];
      continue;
    }
    if ((i - x[0]) % a[0] == 0)
      dp[0][i] = (dp[0][i - 1] + 1) % mod;
    else
      dp[0][i] = dp[0][i - 1];
  }
  for (int i = 1; i < n; i++) {
    dp[i][x[i]] = dp[i - 1][x[i] - 1];
    if (a[i] == 0) {
      for (int j = x[i] + 1; j < l; j++) {
        dp[i][j] = dp[i - 1][j];
      }
      continue;
    }
    for (int j = x[i] + 1; j < l; j++) {
      if ((j - x[i]) % a[i] == 0) {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % mod;
      } else {
        dp[i][j] = dp[i][j - 1];
      }
    }
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < l; j++) {
  //     std::cout << dp[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  std::cout << dp[n - 1][l - 1] << std::endl;
  return 0;
}

Error: 127
/tmp/eae1844b-ff19-4cbb-8cd8-f160cc8ba2f9.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int dp[5010][5010], mod = 1e9 + 7;
int main(int argc, char *argv[]) {
  int n, l;
  cin >> n >> l;
  int x[n], a[n];
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  memset(dp, 0, sizeof(dp));
  dp[0][x[0]] = 1;
  for (int i = x[0] + 1; i < l; i++) {
    if ((i - x[0]) % a[0] == 0)
      dp[0][i] = (dp[0][i - 1] + 1) % mod;
    else
      dp[0][i] = dp[0][i - 1];
  }
  for (int i = 1; i < n; i++) {
    dp[i][x[i]] = dp[i - 1][x[i] - 1];
    for (int j = x[i] + 1; j < l; j++) {
      if ((j - x[i]) % a[i] == 0) {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1]) % mod;
      } else {
        dp[i][j] = dp[i][j - 1];
      }
    }
  }
  // for (int i = 0; i < n; i++) {
  //   for (int j = 0; j < l; j++) {
  //     std::cout << dp[i][j] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  std::cout << dp[n - 1][l - 1] << std::endl;
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Time Limit Exceeded

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

#include <queue>
typedef long long ll;

#include <cstdio>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}

#include <set>

using namespace std;

const ll mod = 1000000007;
class BIT {
  vector<ll> bit;

public:
  BIT(int n) : bit(n + 1) {}
  void add(int idx, ll val) {
    idx++;
    while (idx < (int)bit.size()) {
      (bit[idx] += val) %= mod;
      idx += idx & -idx;
    }
  }
  ll sum(int i) {
    ll s = 0;
    i++;
    while (i > 0) {
      (s += bit[i]) %= mod;
      i -= i & -i;
    }
    return s;
  }

  void swap(BIT &other) { bit.swap(other.bit); }
};

int main() {
  const int n = getInt();
  const int l = getInt();

  vector<int> x(n);
  vector<int> a(n);
  REP(i, n) x[i] = getInt();
  REP(i, n) a[i] = getInt();

  BIT dp(l + 1);
  dp.add(0, 1);

  REP(i, n) {
    BIT next(l + 1);
    const int xx = x[i];
    const int aa = a[i];

    if (aa != 0) {
      for (int p = xx; p < l; p += aa) {
        next.add(p + 1, dp.sum(p));
      }
    } else {
      next.add(xx + 1, dp.sum(xx));
    }

    dp.swap(next);
  }

  printf("%d\\n", (int)dp.sum(l));

  return 0;
}

Error: TLE

Fixed submission:

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

#include <queue>
typedef long long ll;

#include <cstdio>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}

#include <set>

using namespace std;

const ll mod = 1000000007;
class BIT {
  vector<ll> bit;

public:
  BIT(int n) : bit(n + 1) {}
  void add(int idx, ll val) {
    idx++;
    while (idx < (int)bit.size()) {
      (bit[idx] += val) %= mod;
      idx += idx & -idx;
    }
  }
  ll sum(int i) {
    ll s = 0;
    i++;
    while (i > 0) {
      (s += bit[i]) %= mod;
      i -= i & -i;
    }
    return s;
  }

  void swap(BIT &other) { bit.swap(other.bit); }
};

int main() {
  const int n = getInt();
  const int l = getInt();

  vector<int> x(n);
  vector<int> a(n);
  REP(i, n) x[i] = getInt();
  REP(i, n) a[i] = getInt();

  BIT dp(l + 1);
  dp.add(0, 1);

  REP(i, n) {
    BIT next(l + 1);
    const int xx = x[i];
    const int aa = a[i];

    for (int p = xx; p < l; p += aa) {
      next.add(p + 1, dp.sum(p));
    }

    dp.swap(next);
  }

  printf("%d\\n", (int)dp.sum(l));

  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Memory Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll dp[2][5000];

int main() {
  int N, L, X[5000], A[5000];
  cin >> N >> L;
  for (int i = 0; i < N; i++)
    cin >> X[i];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; X[i] + A[i] * j < L; j++) {
      dp[i & 1][X[i] + A[i] * j] = 1;
      if (A[i] == 0)
        break;
    }
    if (i == 0)
      continue;
    ll sum = 0;
    for (int j = 0; j < L; j++) {
      dp[i & 1][j] = (dp[i & 1][j] * sum) % MOD;
      sum += dp[(i - 1) & 1][j] % MOD;
      dp[(i - 1) & 1][j] = 0;
    }
  }
  ll ans = 0;
  for (int i = 0; i < L; i++)
    ans += dp[(N - 1) & 1][i] % MOD;
  printf("%lld\\n", ans % MOD);
  return 0;
}

Error: MLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll dp[5000][5000];

int main() {
  int N, L, X[5000], A;
  cin >> N >> L;
  for (int i = 0; i < N; i++)
    cin >> X[i];
  for (int i = 0; i < N; i++) {
    cin >> A;
    if (A == 0) {
      dp[i][X[i]] = 1;
      continue;
    }
    for (int j = 0; X[i] + A * j < L; j++) {
      dp[i][X[i] + A * j] = 1;
    }
  }
  for (int i = 0; i < N; i++) {
    ll sum = 0;
    for (int j = 0; j < L; j++) {
      dp[i + 1][j] = (dp[i + 1][j] * sum) % MOD;
      sum += dp[i][j] % MOD;
    }
  }
  ll ans = 0;
  for (int i = 0; i < L; i++)
    ans += dp[N - 1][i] % MOD;
  printf("%lld\\n", ans % MOD);
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

using namespace std;

const int M = 1000000007;

int main() {
  int n, l;
  int x[5000], a[5000];
  int count[5000][2];
  int total = 0;
  scanf("%d%d", &n, &l);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x[i]);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < l; ++i) {
    count[i][1] = 0;
  }
  count[x[0]][1] = 1;
  if (a[0] > 0) {
    for (int pos = x[0] + a[0]; pos < l; pos += a[0]) {
      count[pos][1] = 1;
    }
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < l; ++j) {
      count[j][0] = count[j][1];
      count[j][1] = 0;
    }
    for (int j = 0; j < x[i]; ++j) {
      count[x[i]][1] = (count[x[i]][1] + count[j][0]) % M;
    }
    if (a[i] > 0) {
      for (int pos = x[i] + a[i]; pos < l; pos += a[i]) {
        count[pos][1] = count[pos - a[i]][1];
        for (int j = pos - a[i]; j < pos; ++j) {
          count[pos][1] = (count[pos][1] + count[j][0]) % M;
        }
      }
    }
  }
  for (int i = 0; i < l; ++i) {
    total = (total + count[i][1]) % M;
  }
  printf("%d\\n", total);
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>

using namespace std;

const int M = 1000000007;

int main() {
  int n, l;
  int x[5000], a[5000];
  int count[5000][2];
  int total = 0;
  scanf("%d%d", &n, &l);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x[i]);
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < l; ++i) {
    count[i][1] = 0;
  }
  count[x[0]][1] = 1;
  if (a[0] > 0) {
    for (int pos = x[0] + a[0]; pos < l; pos += a[0]) {
      count[pos][1] = 1;
    }
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < l; ++j) {
      count[j][0] = count[j][1];
      count[j][1] = 0;
    }
    for (int j = 0; j < x[i]; ++j) {
      count[x[i]][1] = (count[x[i]][1] + count[j][0]) % M;
    }
    if (a[i] > 0) {
      int loop_num = 0;
      for (int pos = x[i] + a[i]; pos < l; ++pos) {
        count[pos][1] = count[pos - a[i]][1];
        for (int j = pos - a[i]; j < pos; ++j) {
          count[pos][1] = (count[pos][1] + count[j][0]) % M;
          ++loop_num;
          if (loop_num == 1000000) {
            return 100;
          }
        }
      }
    }
  }
  for (int i = 0; i < l; ++i) {
    total = (total + count[i][1]) % M;
  }
  printf("%d\\n", total);
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const int MOD = 1000000007;

int main() {
  int n, len;
  cin >> n >> len;
  vector<int> x(n), a(n);
  for (int i = 0; i < n; ++i)
    cin >> x[i];
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  vector<int> dp(len + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    vector<int> nextDp(len + 1, 0);
    int sum = 0;
    for (int j = 0; j < len; ++j) {
      sum += dp[j];
      sum %= MOD;
      if (x[i] <= j && (a[i] == 0 || (j - x[i]) % a[i] == 0)) {
        nextDp[j + 1] = sum;
        nextDp[j + 1] %= MOD;
        if (a[i] == 0)
          break;
      }
    }
    dp.swap(nextDp);
  }

  int ans = 0;
  for (int i = 0; i <= len; ++i) {
    ans += dp[i];
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const int MOD = 1000000007;

int main() {
  int n, len;
  cin >> n >> len;
  vector<int> x(n), a(n);
  for (int i = 0; i < n; ++i)
    cin >> x[i];
  for (int i = 0; i < n; ++i)
    cin >> a[i];

  vector<int> dp(len + 1, 0);
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    vector<int> nextDp(len + 1, 0);
    int sum = 0;
    for (int j = 0; j < len; ++j) {
      sum += dp[j];
      sum %= MOD;
      if (x[i] <= j && (j - x[i]) % a[i] == 0) {
        nextDp[j + 1] = sum;
        nextDp[j + 1] %= MOD;
      }
    }
    dp.swap(nextDp);
  }

  int ans = 0;
  for (int i = 0; i <= len; ++i) {
    ans += dp[i];
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

const int mod = 1e9 + 7;
int dp[5001][5001] = {};

int main() {
  int n, L;
  scanf(" %d %d", &n, &L);
  vector<int> x(n), a(n);
  rep(i, n) scanf(" %d", &x[i]);
  rep(i, n) scanf(" %d", &a[i]);

  if (a[0] == 0)
    dp[0][x[0]] = 1;
  else
    for (int i = x[0]; i < L; i += a[0])
      dp[0][i] = 1;

  for (int i = 1; i < n; ++i) {
    int sum = 0;
    if (a[i] == 0) {
      rep(j, x[i])(sum += dp[i - 1][j]) %= mod;
      dp[i][x[i]] = sum;
    } else {
      rep(j, L) {
        if (j - x[i] >= 0 && (j - x[i]) % a[i] == 0)
          dp[i][j] = sum;
        (sum += dp[i - 1][j]) %= mod;
      }
    }
  }

  int ans = 0;
  rep(i, L)(ans += dp[n - 1][i]) %= mod;
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define each(itr, c)                                                           \\
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

const int mod = 1e9 + 7;
int dp[5001][5001] = {};

int main() {
  int n, L;
  scanf(" %d %d", &n, &L);
  vector<int> x(n), a(n);
  rep(i, n) scanf(" %d", &x[i]);
  rep(i, n) scanf(" %d", &a[i]);

  for (int i = x[0]; i < L; i += a[0])
    dp[0][i] = 1;

  for (int i = 1; i < n; ++i) {
    int sum = 0;
    rep(j, L) {
      if (j - x[i] >= 0 && (j - x[i]) % a[i] == 0)
        dp[i][j] = sum;
      (sum += dp[i - 1][j]) %= mod;
    }
  }

  int ans = 0;
  rep(i, L)(ans += dp[n - 1][i]) %= mod;
  printf("%d\\n", ans);
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int N, L;
vector<int> x, a;
const int mod = 1000000007;

class Fenwick_Tree {
private:
  vector<int64> p;

public:
  Fenwick_Tree(int size) { p.resize(size + 2, 0); }
  void init() {
    for (int i = 0; i < p.size(); i++)
      p[i] = 0;
  }
  int64 sum(int x) {
    int64 ret = 0;
    if (x < 0)
      return (0);
    for (++x; x > 0; x -= x & -x)
      (ret += p[x]) %= mod;
    return (ret);
  }
  void add(int k, int a) {
    for (++k; k < p.size(); k += k & -k)
      (p[k] += a) %= mod;
  }
};

vector<Fenwick_Tree> dp;
int main() {
  cin >> N >> L;
  ++L;
  dp.resize(2, Fenwick_Tree(L + 5));
  x.resize(N), a.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    ++x[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  dp[0].add(0, 1);
  for (int i = 1; i <= N; i++) {
    if (a[i - 1] == 0) {
      dp[i & 1].add(x[i - 1], dp[(i - 1) & 1].sum(x[i - 1] - 1));
    } else {
      for (int j = L - 1; j >= x[i - 1]; j--) { // ????????????
        if ((j - x[i - 1]) % a[i - 1] == 0) {   // ?§??????????
          dp[i & 1].add(j, dp[(i - 1) & 1].sum(j - 1));
        }
      }
    }
    dp[(i - 1) & 1].init();
  }
  cout << dp[N & 1].sum(L) << endl;
}

Error: MLE

Fixed submission:

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

int N, L;
vector<int> x, a;
const int mod = 1000000007;

class Fenwick_Tree {
private:
  vector<int64> p;

public:
  Fenwick_Tree(int size) { p.resize(size + 2, 0); }
  int64 sum(int x) {
    int64 ret = 0;
    if (x < 0)
      return (0);
    for (++x; x > 0; x -= x & -x)
      (ret += p[x]) %= mod;
    return (ret);
  }
  void add(int k, int a) {
    for (++k; k < p.size(); k += k & -k)
      (p[k] += a) %= mod;
  }
};

vector<Fenwick_Tree> dp;
int main() {
  cin >> N >> L;
  ++L;
  dp.resize(N + 1, Fenwick_Tree(L + 5));
  x.resize(N), a.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    ++x[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  dp[0].add(0, 1);
  for (int i = 1; i <= N; i++) {
    if (a[i - 1] == 0) {
      dp[i].add(x[i - 1], dp[i - 1].sum(x[i - 1] - 1));
    } else {
      for (int j = L - 1; j >= x[i - 1]; j--) { // ????????????
        if ((j - x[i - 1]) % a[i - 1] == 0) {   // ?§??????????
          dp[i].add(j, dp[i - 1].sum(j - 1));
        }
      }
    }
  }
  cout << dp[N].sum(L) << endl;
}
Problem p01769 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, L;
  int x[5010], a[5010];

  scanf("%d %d", &N, &L);

  for (int i = 0; i < N; i++)
    scanf("%d", x + i);
  for (int i = 0; i < N; i++)
    scanf("%d", a + i);

  int dp[2][5010] = {{0}};
  int prev = 0, now = 1;

  dp[prev][L] = 1;
  for (int i = N - 1; i >= 0; i--) {
    for (int j = L; j >= 0; j--) {
      dp[now][j] = 0;
      dp[prev][j] = (dp[prev][j] + dp[prev][j + 1]) % 1000000007;
    }
    for (int j = x[i]; j < L; j += a[i]) {
      dp[now][j] = dp[prev][j + 1];
      if (!a[i])
        break;
    }
    now = 1 - now;
    prev = 1 - prev;
  }

  int ans = 0;

  for (int i = 0; i < L; i++)
    ans = (ans + dp[prev][i]) % 1000000007;

  printf("%d\\n", ans);

  return (0);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, L;
  int x[5010], a[5010];

  scanf("%d %d", &N, &L);

  for (int i = 0; i < N; i++)
    scanf("%d", x + i);
  for (int i = 0; i < N; i++)
    scanf("%d", a + i);

  int dp[2][5010] = {{0}};
  int prev = 0, now = 1;

  dp[prev][L] = 1;
  for (int i = N - 1; i >= 0; i--) {
    for (int j = L; j >= 0; j--) {
      dp[now][j] = 0;
      dp[prev][j] = (dp[prev][j] + dp[prev][j + 1]) % 1000000007;
    }
    for (int j = x[i]; j < L; j += a[i]) {
      dp[now][j] = dp[prev][j + 1];
    }
    now = 1 - now;
    prev = 1 - prev;
  }

  int ans = 0;

  for (int i = 0; i < L; i++)
    ans = (ans + dp[prev][i]) % 1000000007;

  printf("%d\\n", ans);

  return (0);
}
Problem p01769 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (1000000007)

int n, L, x[6000], a[6000];
int dp[6000], s[6000];

int main() {
  scanf("%d%d", &n, &L);
  rep(i, n) scanf("%d", x + i);
  rep(i, n) scanf("%d", a + i);
  dp[L] = 1;
  for (int k = n - 1; k >= 0; k--) {
    for (int i = L; i >= 0; i--) {
      s[i] = (s[i + 1] + dp[i]) % MOD;
      if (a[k] == 0) {
        if (i == x[k])
          dp[i] = s[i + 1];
        else
          dp[i] = 0;
      } else {
        if (i >= x[k] && (i - x[k]) % a[k] == 0)
          dp[i] = s[i + 1];
        else
          dp[i] = 0;
      }
    }
  }
  int ans = 0;
  rep(i, L) ans = (ans + dp[i]) % MOD;
  printf("%d\\n", (int)ans);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (1000000007LL)

int n, L, x[6000], a[6000];
int dp[6000], s[6000];

int main() {
  scanf("%d%d", &n, &L);
  rep(i, n) scanf("%d", x + i);
  rep(i, n) scanf("%d", a + i);
  dp[L] = 1;
  for (int k = n - 1; k >= 0; k--) {
    for (int i = L; i >= 0; i--) {
      s[i] = (s[i + 1] + dp[i]) % MOD;
      if (i >= x[k] && (i - x[k]) % a[k] == 0)
        dp[i] = s[i + 1];
      else
        dp[i] = 0;
    }
  }
  int ans = 0;
  rep(i, L) ans = (ans + dp[i]) % MOD;
  printf("%d\\n", (int)ans);
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++)
#define EQ(a, b) (abs((a) - (b)) < eps)
#define MOD 1000000007
int N, L;
int x[5010], a[5010];
int dp[5010][5010];
int rec(int i, int j) {
  if (j == N)
    return 1ll;
  if (i == L)
    return 0ll;
  if (dp[i][j] != -1)
    return dp[i][j];
  ll res = rec(i + 1, j);
  if ((a[j] == 0 && i == x[j]) ||
      (a[j] != 0 && i >= x[j] && (i - x[j]) % a[j] == 0))
    res = (res + rec(i + 1, j + 1)) % MOD;
  return dp[i][j] = res;
}
int main() {
  scanf("%d %d", &N, &L);
  rep(i, N) scanf("%d", &x[i]);
  rep(i, N) scanf("%d", &a[i]);
  memset(dp, -1, sizeof(dp));
  printf("%d\\n", rec(0, 0));
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++)
#define EQ(a, b) (abs((a) - (b)) < eps)
#define MOD 1000000007
int N, L;
int x[5010], a[5010];
ll dp[5010][5010];
ll rec(int i, int j) {
  if (j == N)
    return 1ll;
  if (i == L)
    return 0ll;
  if (dp[i][j] != -1)
    return dp[i][j];
  ll res = rec(i + 1, j);
  if ((a[j] == 0 && i == x[j]) ||
      (a[j] != 0 && i >= x[j] && (i - x[j]) % a[j] == 0))
    res = (res + rec(i + 1, j + 1)) % MOD;
  return dp[i][j] = res;
}
int main() {
  scanf("%d %d", &N, &L);
  rep(i, N) scanf("%d", &x[i]);
  rep(i, N) scanf("%d", &a[i]);
  memset(dp, -1, sizeof(dp));
  printf("%lld\\n", rec(0, 0));
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int dp[5010][5010] = {0};
int main() {
  int n, l;
  cin >> n >> l;
  int MOD = 1000000007;
  vi x(n), a(n);
  rep(i, n) cin >> x[i];
  rep(i, n) cin >> a[i];
  rep(i, 5010) dp[0][i] = 1;
  rep(i, n) {
    for (int j = x[i] + 1; j <= l; j++) {
      if (j == x[i] + 1 || a[i] && (j - x[i] - 1) % a[i] == 0)
        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - 1]) % MOD;
      dp[i + 1][j] = (dp[i + 1][j] + dp[i + 1][j - 1]) % MOD;
    }
  }
  cout << dp[n][l] << endl;
}

Error: 127
/tmp/6e594b3f-a4af-4a5d-a6e8-9aad887c798b.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
int dp[5010][5010] = {0};
int main() {
  int n, l;
  cin >> n >> l;
  int MOD = 1000000007;
  vi x(n), a(n);
  rep(i, n) cin >> x[i];
  rep(i, n) cin >> a[i];
  rep(i, 5010) dp[0][i] = 1;
  rep(i, n) {
    for (int j = x[i] + 1; j <= l; j++) {
      if ((j - x[i] - 1) % a[i] == 0)
        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - 1]) % MOD;
      dp[i + 1][j] = (dp[i + 1][j] + dp[i + 1][j - 1]) % MOD;
    }
  }
  cout << dp[n][l] << endl;
}