alexjercan/bugnet huggingface dataset:
Problem p01769 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
int N, L;
ll c[2][5001], mod = 1e9 + 7;
ll x[5000], a[5000];
void add(ll &x, ll y) {
  x += y;
  x %= mod;
}
int main() {
  cin >> N >> L;
  rep(i, N) cin >> x[i];
  rep(i, N) cin >> a[i];
  rep(i, N) {
    int id = N - 1 - i;
    ll sum = 0;
    if (i == 0)
      sum = 1;
    rep(j, 5001) c[1 - i % 2][j] = 0;
    for (int j = L - 1; j >= x[id]; j--) {
      if (a[id] != 0 && (j - x[id]) % a[id] == 0)
        add(c[1 - i % 2][j], sum);
      if (a[id] == 0 && j == x[id])
        add(c[1 - i % 2][j], sum);
      sum += c[i % 2][j];
    }
  }
  ll ans = 0;
  rep(i, L) add(ans, c[N % 2][i]);
  cout << ans << endl;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
int N, L;
ll c[5001][5001], mod = 1e9 + 7;
ll x[5000], a[5000];
void add(ll &x, ll y) {
  x += y;
  x %= mod;
}
int main() {
  cin >> N >> L;
  rep(i, N) cin >> x[i];
  rep(i, N) cin >> a[i];
  rep(i, N) {
    int id = N - 1 - i;
    ll sum = 0;
    if (i == 0)
      sum = 1;
    for (int j = L - 1; j >= x[id]; j--) {
      if (a[id] != 0 && (j - x[id]) % a[id] == 0)
        add(c[i + 1][j], sum);
      if (a[id] == 0 && j == x[id])
        add(c[i + 1][j], sum);
      sum += c[i][j];
    }
  }
  ll ans = 0;
  rep(i, L) add(ans, c[N][i]);
  cout << ans << endl;
}
Problem p01769 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>
using namespace std;
long long mod = 1000000007;
int c[5100];
int d[5100];
int dp[5100][5100];
int sum[5100][5100];
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 0; i < a; i++)
    scanf("%d", c + i);
  for (int i = 0; i < a; i++)
    scanf("%d", d + i);
  for (int i = c[0]; i < b; i += d[0]) {
    dp[1][i] = 1;
    if (d[0] == 0)
      break;
  }
  sum[1][0] = dp[1][0];
  for (int i = 1; i < b; i++) {
    sum[1][i] = (dp[1][i] + sum[1][i - 1]) % mod;
  }
  for (int i = 1; i < a; i++) {
    for (int j = c[i]; j < b; j += d[i]) {
      if (j)
        dp[i + 1][j] = sum[i][j - 1];
      if (d[i] == 0)
        break;
    }
    for (int j = 1; j < b; j++)
      sum[i + 1][j] = (dp[i + 1][j] + sum[i + 1][j - 1]) % mod;
  }
  printf("%lld\\n", sum[a][b - 1]);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
long long mod = 1000000007;
int c[5100];
int d[5100];
int dp[5100][5100];
int sum[5100][5100];
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  for (int i = 0; i < a; i++)
    scanf("%d", c + i);
  for (int i = 0; i < a; i++)
    scanf("%d", d + i);
  for (int i = c[0]; i < b; i += d[0]) {
    dp[1][i] = 1;
  }
  sum[1][0] = dp[1][0];
  for (int i = 1; i < b; i++) {
    sum[1][i] = (dp[1][i] + sum[1][i - 1]) % mod;
  }
  for (int i = 1; i < a; i++) {
    for (int j = c[i]; j < b; j += d[i]) {
      if (j)
        dp[i + 1][j] = sum[i][j - 1];
    }
    for (int j = 1; j < b; j++)
      sum[i + 1][j] = (dp[i + 1][j] + sum[i + 1][j - 1]) % mod;
  }
  printf("%lld\\n", sum[a][b - 1]);
}
Problem p01769 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define REP(i, a, b) for (int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

template <class T> inline void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}

constexpr int mod = 1000000007;

inline int add(int a, int b) {
  const int res = a + b;
  return res >= mod ? res - mod : res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, l;
  cin >> n >> l;

  vector<int> x(n), a(n);
  for (auto &e : x)
    cin >> e;
  for (auto &e : a) {
    cin >> e;
    if (e == 0)
      e = l + 1;
  }

  vector<int> dp(l + 1, 0);
  dp[l] = 1;

  for (int i = n - 1; i >= 0; --i) {
    vector<int> next_dp(l + 1, 0);

    int sum = 0;
    for (int j = l; j >= x[i]; --j) {
      if ((j - x[i]) % a[i] == 0) {
        next_dp[j] = sum;
      }
      sum = add(sum, dp[j]);
    }
    dp = move(next_dp);
  }

  cout << accumulate(begin(dp), end(dp), 0, add) << endl;

  return EXIT_SUCCESS;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define REP(i, a, b) for (int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) begin(x), end(x)

template <class T> inline void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}
template <class T> inline void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}

constexpr int mod = 1000000007;

inline int add(int a, int b) {
  const int res = a + b;
  return res >= mod ? res - mod : res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int n, l;
  cin >> n >> l;

  vector<int> x(n), a(n);
  for (auto &e : x)
    cin >> e;
  for (auto &e : a)
    cin >> e;

  vector<int> dp(l + 1, 0);
  dp[l] = 1;

  for (int i = n - 1; i >= 0; --i) {
    vector<int> next_dp(l + 1, 0);

    int sum = 0;
    for (int j = l; j >= x[i]; --j) {
      if ((j - x[i]) % a[i] == 0) {
        next_dp[j] = sum;
      }
      sum = add(sum, dp[j]);
    }
    dp = move(next_dp);
  }

  cout << accumulate(begin(dp), end(dp), 0, add) << endl;

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

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 5010;

ll d[MAX_N];

int main() {
  int n, L;
  scanf("%d %d", &n, &L);
  vi x(n), a(n);
  rep(i, n) scanf("%d", &x[i]);
  rep(i, n) scanf("%d", &a[i]);
  {
    if (a.back() != 0) {
      for (int i = x.back(); i < L; i += a.back()) {
        d[i] = 1;
      }
    } else {
      d[x.back()] = 1;
    }
  }
  repr(i, n - 1) {
    ll sum = 0LL;
    rep(j, L)(sum += d[j]) %= MOD;
    if (a[i] == 0) {
      rep(j, x[i] + 1) {
        sum -= d[j];
        (sum += MOD) %= MOD;
      }
      d[x[i]] = sum;
      REP(j, x[i] + 1, L) d[j] = 0;
      continue;
    }
    rep(j, L) {
      if (j < x[i] || (j - x[i]) % a[i] != 0 || j >= L - (n - 1 - i)) {
        sum -= d[j];
        (sum += MOD) %= MOD;
        d[j] = 0;
      } else {
        sum -= d[j];
        (sum += MOD) %= MOD;
        d[j] = sum;
      }
    }
  }
  ll ans = 0LL;
  rep(i, L)(ans += d[i]) %= MOD;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 5010;

ll d[MAX_N];

int main() {
  int n, L;
  scanf("%d %d", &n, &L);
  vi x(n), a(n);
  rep(i, n) scanf("%d", &x[i]);
  rep(i, n) scanf("%d", &a[i]);
  {
    for (int i = x.back(); i < L; i += a.back()) {
      d[i] = 1;
    }
  }
  repr(i, n - 1) {
    ll sum = 0LL;
    rep(j, L)(sum += d[j]) %= MOD;
    rep(j, L) {
      if (j < x[i] || (j - x[i]) % a[i] != 0 || j >= L - (n - 1 - i)) {
        sum -= d[j];
        (sum += MOD) %= MOD;
        d[j] = 0;
      } else {
        sum -= d[j];
        (sum += MOD) %= MOD;
        d[j] = sum;
      }
    }
  }
  ll ans = 0LL;
  rep(i, L)(ans += d[i]) %= MOD;
  cout << ans << endl;
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>

typedef long long ll;

const ll MOD = 1000000007ll;

int N, L;
int X[5000], A[5000];
ll BIT[2][5001];

inline void add(int k, ll v, ll (&bit)[5001]) {
  k += 1;
  while (k <= L) {
    bit[k] = (bit[k] + v) % MOD;
    k += k & -k;
  }
}

inline ll sum(int k, ll (&bit)[5001]) {
  k += 1;
  ll res = 0ll;
  while (k > 0) {
    res = (res + bit[k]) % MOD;
    k -= k & -k;
  }
  return res;
}

int main() {
  scanf("%d %d", &N, &L);

  for (int i = 0; i < N; i++) {
    scanf("%d", X + i);
    X[i] = L - 1 - X[i];
  }
  std::reverse(X, X + N);

  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
  }
  std::reverse(A, A + N);

  if (A[0] == 0) {
    add(X[0], 1, BIT[0]);
  } else {
    for (int i = X[0]; i >= 0; i -= A[0]) {
      add(i, 1, BIT[0]);
    }
  }

  int prev = 0, next = 1;
  for (int i = 1; i < N; i++) {
    memset(BIT[next], 0, sizeof(BIT[next]));

    if (A[i] == 0) {
      add(X[i], sum(X[i] - 1, BIT[prev]), BIT[next]);
    } else {
      for (int j = X[i]; j >= 0; j -= A[i]) {
        add(j, sum(j - 1, BIT[prev]), BIT[next]);
      }
    }

    std::swap(prev, next);
  }

  printf("%lld\\n", sum(L - 1, BIT[prev]));
}

Error: TLE

Fixed submission:

// ???????????????????????¶?????????

#include <algorithm>
#include <cstring>
#include <iostream>

typedef long long ll;

const ll MOD = 1000000007ll;

int N, L;
int X[5000], A[5000];
ll BIT[2][5001];

void add(int k, ll v, ll (&bit)[5001]) {
  k += 1;
  while (k <= L) {
    bit[k] = (bit[k] + v) % MOD;
    k += k & -k;
  }
}

ll sum(int k, ll (&bit)[5001]) {
  k += 1;
  ll res = 0ll;
  while (k > 0) {
    res = (res + bit[k]) % MOD;
    k -= k & -k;
  }
  return res;
}

int main() {
  scanf("%d %d", &N, &L);

  for (int i = 0; i < N; i++) {
    scanf("%d", X + i);
    X[i] = L - 1 - X[i];
  }
  std::reverse(X, X + N);

  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
  }
  std::reverse(A, A + N);

  for (int i = X[0]; i >= 0; i -= A[0]) {
    add(i, 1, BIT[0]);
  }

  int prev = 0, next = 1;
  for (int i = 1; i < N; i++) {
    memset(BIT[next], 0, sizeof(BIT[next]));

    if (A[i] == 0) {
      add(X[i], sum(X[i] - 1, BIT[prev]), BIT[next]);
    } else {
      for (int j = X[i]; j >= 0; j -= A[i]) {
        add(j, sum(j - 1, BIT[prev]), BIT[next]);
      }
    }

    std::swap(prev, next);
  }

  printf("%lld\\n", sum(L - 1, BIT[prev]));
}
Problem p01769 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define MAX 5050
typedef long long ll;
const ll MOD = ((1e9) + 7);

int dp[MAX][MAX];

int main() {
  int N, L;
  cin >> N >> L;
  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];
  }

  for (int i = 0; i < L; i++) {
    dp[0][i] = 1;
  }

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

    for (int j = x[i]; j < L; j++) {
      dp[i + 1][j + 1] += dp[i + 1][j];
      dp[i + 1][j + 1] %= MOD;
    }
  }

  cout << dp[N][L - 1] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define MAX 5050
typedef long long ll;
const ll MOD = ((1e9) + 7);

int dp[MAX][MAX];

int main() {
  int N, L;
  cin >> N >> L;
  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];
  }

  for (int i = 0; i < L; i++) {
    dp[0][i] = 1;
  }

  for (int i = 0; i < N; i++) {
    for (int j = x[i]; j < L; j += a[i]) {
      if (j > 0)
        dp[i + 1][j] += dp[i][j - 1];
      else {
        dp[i + 1][j] = dp[i][j];
      }

      dp[i + 1][j] %= MOD;
    }

    for (int j = x[i]; j < L; j++) {
      dp[i + 1][j + 1] += dp[i + 1][j];
      dp[i + 1][j + 1] %= MOD;
    }
  }

  cout << dp[N][L - 1] << endl;
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#pragma warning(disable : 4996)
int N, L, x[5000], a[5000], dp[5001][5001];
int main() {
  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]), a[i] = a[i] ? a[i] : L;
  dp[N][L] = 1;
  for (int i = N - 1; i >= 0; i--) {
    int sum = dp[i + 1][L];
    for (int j = L - 1; j >= 0; j--) {
      if (j >= x[i] && (j - x[i]) % a[i] == 0) {
        dp[i][j] = sum;
      }
      sum = (sum + dp[i + 1][j]) % 1000000007;
    }
  }
  int ret = 0;
  for (int i = 0; i < L; i++)
    ret = (ret + dp[0][i]) % 1000000007;
  printf("%d\\n", ret);
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
int N, L, x[5000], a[5000], dp[5001][5001];
int main() {
  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]), a[i] = a[i] ? a[i] : L;
  dp[N][L] = 1;
  for (int i = N - 1; i >= 0; i--) {
    int sum = dp[i - 1][L];
    for (int j = L - 1; j >= 0; j--) {
      if (j >= x[i] && (j - x[i]) % a[i] == 0) {
        dp[i][j] = sum;
      }
      sum = (sum + dp[i - 1][j]) % 1000000007;
    }
  }
  int ret = 0;
  for (int i = 0; i < L; i++)
    ret = (ret + dp[0][i]) % 1000000007;
  printf("%d\\n", ret);
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

#define MOD 1000000007

long long N, L;
long long x[6000], a[6000];
long long dp[6000][6000];

int main() {
  cin >> N >> L;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = x[N - 1]; i < L; i += a[N - 1]) {
    cnt++;
    if (cnt >= 20000) {
      break;
    }
    dp[N - 1][i] = 1;
  }
  for (int i = L - 1; i >= 0; i--) {
    dp[N - 1][i] += dp[N - 1][i + 1];
  }
  for (int i = N - 2; i >= 0; i--) {
    cnt = 0;
    for (int j = x[i]; j < L; j += a[i]) {
      cnt++;
      if (cnt >= 20000) {
        break;
      }
      dp[i][j] = dp[i + 1][j + 1];
    }
    for (int j = L - 1; j >= 0; j--) {
      dp[i][j] += dp[i][j + 1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[0][0] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

#define MOD 1000000007

long long N, L;
long long x[6000], a[6000];
long long dp[6000][6000];

int main() {
  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 = x[N - 1]; i < L; i += a[N - 1]) {
    dp[N - 1][i] = 1;
  }
  for (int i = L - 1; i >= 0; i--) {
    dp[N - 1][i] += dp[N - 1][i + 1];
  }
  for (int i = N - 2; i >= 0; i--) {
    for (int j = x[i]; j < L; j += a[i]) {
      dp[i][j] = dp[i + 1][j + 1];
    }
    for (int j = L - 1; j >= 0; j--) {
      dp[i][j] += dp[i][j + 1];
      dp[i][j] %= MOD;
    }
  }
  cout << dp[0][0] << endl;
  return 0;
}
Problem p01769 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, b) FOR(i, 0, b)
#define F first
#define S second
#define PB push_back
#define BE(c) c.begin(), c.end()
using namespace std;
typedef long long LL;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut, ut> pr;
typedef vector<pr> Vpr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
const int SIZE = 100 + 5 * 1e+3;
const LL p = 7 + 1e+9;
LL DP[3][SIZE];
LL fx[SIZE], jump[SIZE];
LL N, L;
int main() {
  cin >> N >> L;
  FOR(i, 1, N + 1) {
    cin >> fx[i];
    fx[i]++;
  }
  FOR(i, 1, N + 1)
  cin >> jump[i];
  LL ans = 0;
  REP(i, 2)
  DP[i][0] = 1;
  FOR(k, 1, L + 1) {
    LL i = k & 1;
    FOR(j, 1, N + 1) {
      ans = 0;
      if (jump[j] != 0 && (k - fx[j]) >= 0 && (k - fx[j]) % jump[j] == 0)
        ans += DP[i ^ 1][j - 1];
      if (jump[j] == 0 && k == fx[j])
        ans += DP[i ^ 1][j - 1];
      ans += DP[i ^ 1][j];
      DP[i][j] = ans % p;
    }
  }
  cout << DP[L & 1][N] << endl;
  //	cout << search(0,fx[0]) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, b) FOR(i, 0, b)
#define F first
#define S second
#define PB push_back
#define BE(c) c.begin(), c.end()
using namespace std;
typedef long long LL;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut, ut> pr;
typedef vector<pr> Vpr;
typedef priority_queue<pr, Vpr, greater<pr>> PQ;
const int SIZE = 100 + 5 * 1e+3;
const LL p = 7 + 1e+9;
LL DP[3][SIZE];
LL fx[SIZE], jump[SIZE];
LL N, L;
LL search(int now, int s) {
  LL ans = 0;
  if (now == N)
    return 1;
  if (s >= L)
    return 0;
  if (DP[now][s] != -1)
    return (LL)DP[now][s];
  ans = search(now, s + 1);
  if ((s - fx[now]) >= 0 && (s - fx[now]) % jump[now] == 0)
    ans += search(now + 1, s + 1);
  return (LL)(DP[now][s] = (int)(ans % p));
}
int main() {
  cin >> N >> L;
  FOR(i, 1, N + 1) {
    cin >> fx[i];
    fx[i]++;
  }
  FOR(i, 1, N + 1)
  cin >> jump[i];
  LL ans = 0;
  REP(i, 2)
  DP[i][0] = 1;
  FOR(k, 1, L + 1) {
    int i = k & 1;
    FOR(j, 1, N + 1) {
      ans = 0;
      if ((k - fx[j]) >= 0 && (k - fx[j]) % jump[j] == 0)
        ans += DP[i ^ 1][j - 1];
      ans += DP[i ^ 1][j];
      DP[i][j] = ans % p;
    }
  }
  cout << DP[L & 1][N] << endl;
  //	cout << search(0,fx[0]) << endl;
}
Problem p01769 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i, n) for (int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int x[5000], a[5000];
int dp[2][5010];
const int MOD = ten(9) + 7;

int main() {
  int n, l;
  scanf("%d%d", &n, &l);
  FOR(i, n) scanf("%d", x + i);
  FOR(i, n) scanf("%d", a + i);
  FOR(i, n) x[i]++;

  FOR(i, l + 1) dp[0][i] = 1;
  auto pv = dp[0], nt = dp[1];
  FOR(i, n) {
    memset(nt, 0, sizeof(dp[0]));
    if (a[i]) {
      for (int dist = 0; x[i] + dist <= l; dist += a[i]) {
        int cur = x[i] + dist;
        nt[cur] = pv[cur - 1];
      }
    } else {
      nt[x[i]] = pv[x[i] - 1];
    }
    FOR(j, l) {
      nt[j + 1] += nt[j];
      if (nt[j + 1] >= MOD)
        nt[j + 1] -= MOD;
    }
    swap(pv, nt);
  }
  cout << pv[l] << endl;
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i, n) for (int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int x[5000], a[5000];
int dp[2][5010];
const int MOD = ten(9) + 7;

int main() {
  int n, l;
  scanf("%d%d", &n, &l);
  FOR(i, n) scanf("%d", x + i);
  FOR(i, n) scanf("%d", a + i);
  FOR(i, n) x[i]++;

  FOR(i, l + 1) dp[0][i] = 1;
  auto pv = dp[0], nt = dp[1];
  FOR(i, n) {
    memset(nt, 0, sizeof(dp[0]));
    for (int dist = 0; x[i] + dist <= l; dist += a[i]) {
      int cur = x[i] + dist;
      nt[cur] = pv[cur - 1];
    }
    FOR(j, l) {
      nt[j + 1] += nt[j];
      if (nt[j + 1] >= MOD)
        nt[j + 1] -= MOD;
    }
    swap(pv, nt);
  }
  cout << pv[l] << endl;
}
Problem p01769 (C++) — buggy submission, verdict: Runtime Error

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

int dp[5010][5010];

signed main() {
  int n, l, p = 1000000007;
  cin >> n >> l;
  vector<int> x(n), a(n);
  for (int i = 0; i < n; i++)
    cin >> x[n - 1 - i];
  for (int i = 0; i < n; i++)
    cin >> a[n - 1 - 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;
    for (int j = l - 1; j >= x[i]; j--) {
      if ((a[i] > 0 && (j - x[i]) % a[i] == 0) || x[i] == j) {
        dp[i][j] += sum;
        dp[i][j] %= p;
      }
      sum += dp[i - 1][j];
      sum %= p;
    }
  }
  int ans = 0;
  for (int i = 0; i < l; i++) {
    ans += dp[n - 1][i];
    ans %= p;
  }
  cout << ans << endl;
  return 0;
}


Error: -11

Fixed submission:

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

int dp[5010][5010];

signed main() {
  int n, l, p = 1000000007;
  cin >> n >> l;
  vector<int> x(n), a(n);
  for (int i = 0; i < n; i++)
    cin >> x[n - 1 - i];
  for (int i = 0; i < n; i++)
    cin >> a[n - 1 - 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;
    for (int j = l - 1; j >= x[i]; j--) {
      if ((j - x[i]) % a[i] == 0) {
        if (a[i] > 0 || x[i] == j) {
          dp[i][j] += sum;
          dp[i][j] %= p;
        }
      }
      sum += dp[i - 1][j];
      sum %= p;
    }
  }
  int ans = 0;
  for (int i = 0; i < l; i++) {
    ans += dp[n - 1][i];
    ans %= p;
  }
  cout << ans << endl;
  return 0;
}