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

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

struct listnode {
  int val;
  listnode *next;
};
vector<int> func(vector<int> a, vector<int> l, int sum) {
  vector<int> k, val;
  for (int i = 0; i < l.size(); i++)
    if (l[i] == 0) {
      k.push_back(i);
      val.push_back(a[i]);
    }
  if (sum < 0)
    return a;
  else {
    sort(val.rbegin(), val.rend());
    for (int i = 0; i < k.size(); i++)
      a[k[i]] = val[i];
  }
  return a;
}

int32_t main() {
  int m = 1000000007;

  int n;
  cin >> n;
  int dp[2001];
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  dp[6] = 2;
  dp[7] = 3;
  for (int i = 8; i < n + 1; i++)
    dp[i] = (dp[i - 3] + dp[i - 1]) % m;
  cout << dp[n] % m << endl;
  return 0;
}

Error: 0

Fixed submission:

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

struct listnode {
  int val;
  listnode *next;
};
vector<int> func(vector<int> a, vector<int> l, int sum) {
  vector<int> k, val;
  for (int i = 0; i < l.size(); i++)
    if (l[i] == 0) {
      k.push_back(i);
      val.push_back(a[i]);
    }
  if (sum < 0)
    return a;
  else {
    sort(val.rbegin(), val.rend());
    for (int i = 0; i < k.size(); i++)
      a[k[i]] = val[i];
  }
  return a;
}

int32_t main() {
  int m = 1000000007;

  int n;
  cin >> n;
  int dp[2001];
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  dp[6] = 2;
  dp[7] = 3;
  for (int i = 8; i <= n + 1; i++)
    dp[i] = (dp[i - 3] + dp[i - 1]) % m;
  cout << dp[n] % m << endl;
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 13;
const int mod = 1e9 + 7;
ll c[2013][2013];
int main() {
  int s;
  scanf("%d", &s);
  c[1][0] = 1ll;
  c[0][0] = 0ll;
  for (int i = 1; i <= 2003; i++) {
    for (int j = 0; j <= 2003; j++) {
      c[i][j] = 0;
    }
  }
  for (int i = 1; i <= 2003; i++) {
    for (int j = 0; j <= i; j++) {
      if (i == j) {
        c[i][j] = 1;
        continue;
      }
      if (i && j)
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
      if (j == 0)
        c[i][j] = 1ll;
    }
  }
  if (s <= 3) {
    if (s < 3)
      printf("%d", 0);
    else if (s == 3)
      printf("1");
    return 0;
  }
  int mx = s / 2;
  ll ans = 0;
  for (int i = 1; i <= mx; i++) {
    if (s - i * 2 == 0)
      continue;
    ans += c[s - i * 2 - 1][i - 1];
    ans %= mod;
  }
  printf("%lld", ans);
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 13;
const int mod = 1e9 + 7;
ll c[2013][2013];
int main() {
  int s;
  scanf("%d", &s);
  c[1][0] = 1ll;
  c[0][0] = 0ll;
  for (int i = 1; i <= 5003; i++) {
    for (int j = 0; j <= i; j++) {
      if (i == j) {
        c[i][j] = 1;
        continue;
      }
      if (i && j)
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
      if (j == 0)
        c[i][j] = 1ll;
    }
  }
  if (s <= 3) {
    printf("%d", 0);
    return 0;
  }
  int mx = s / 2;
  ll ans = 0;
  for (int i = 1; i <= mx; i++) {
    if (s - i * 2 == 0)
      continue;
    ans += c[s - i * 2 - 1][i - 1];
    ans %= mod;
  }
  printf("%lld", ans);
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

const int mod = 1000000007;

int a(vector<int> &dp, int S) {
  if (S <= 2)
    return 0;
  if (S <= 5)
    return 1;
  if (dp[S] >= 0)
    return dp[S];
  int ans = 0;
  for (int i = 3; i < S; i++) {
    ans += a(dp, S - i);
    ans %= mod;
  }
  ans++;
  dp[S] = ans;
  return ans;
}

signed main() {
  int S;
  cin >> S;
  vector<int> dp(S + 1, -1);

  if (S <= 2) {
    cout << 0 << endl;
    return 0;
  }
  if (S <= 5) {
    cout << 1 << endl;
    return 0;
  }

  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  cout << a(dp, S) << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

const int mod = 1000000007;

int a(vector<int> &dp, int S) {
  if (S <= 2)
    return 0;
  if (S <= 5)
    return 1;
  if (dp[S] >= 0)
    return dp[S];
  int ans = 0;
  for (int i = 3; i < S; i++) {
    ans += a(dp, S - i);
    ans %= mod;
  }
  ans++;
  dp[S] = ans;
  return ans;
}

signed main() {
  int S;
  cin >> S;
  vector<int> dp(S + 1, -1);

  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;

  cout << a(dp, S) << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int mod = 1e9 + 7;
ll c[2010][2010];
void init(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      if (!j)
        c[i][j] = 1;
      else
        c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0), cin.tie(0);
  int s;
  cin >> s;
  init(2005);
  ll ans = 0;
  for (int i = 1; i * 2 <= s - 1; i++) {
    ans = (ans + c[s - 2 * i - 1][i - 1]) % mod;
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;
const int mod = 1e9 + 7;
ll c[2010][2010];
void init(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      if (!j)
        c[i][j] = 1;
      else
        c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0), cin.tie(0);
  int s;
  cin >> s;
  init(2005);
  ll ans = 0;
  for (int i = 1; i * 2 <= s; i++) {
    ans = (ans + c[s - 2 * i - 1][i - 1]) % mod;
  }
  cout << ans << endl;
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma GCC optimize("O3")
#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#define forr(i, a, b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define input                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);

const double PI = acos(-1.0);
using namespace std;
// typedef pair<double,double>pdd;
typedef long long ll;
typedef pair<ll, ll> pii;
// typedef complex<double> point;
// int x[8]={1,0,0,-1,-1,-1,1,1};
// int y[8]={0,1,-1,0,-1,1,-1,1};
// char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 1000000 + 9;
ll n, ans, mod = 1e9 + 7, mem[2009];

ll dp(int sum) {
  if (!sum)
    return 1;
  ll &ret = mem[sum];
  if (~ret)
    return ret;

  ret = 0;
  forr(j, 3, n) {
    if (j <= sum)
      ret += dp(sum - j), ret %= mod;
  }
  return ret;
}
int main() {
  // freopen("calc.in","r",stdin);
  // freopen("calc.out","w",stdout);
  //__builtin_popcount()
  input cin >> n;
  memset(mem, -1, sizeof mem);
  cout << dp(n) << endl;

  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#include <algorithm>
#include <bits/stdc++.h>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#define forr(i, a, b) for (int i = a; i <= b; i++)
#define F first
#define S second
#define input                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);

const double PI = acos(-1.0);
using namespace std;
// typedef pair<double,double>pdd;
typedef long long ll;
typedef pair<ll, ll> pii;
// typedef complex<double> point;
// int x[8]={1,0,0,-1,-1,-1,1,1};
// int y[8]={0,1,-1,0,-1,1,-1,1};
// char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 1000000 + 9;
ll n, ans, mod = 1e9 + 7, mem[2009][2009];

ll dp(int i, int sum) {
  if (sum == n)
    return 1;
  ll &ret = mem[i][sum];
  if (~ret)
    return ret;

  ret = 0;
  forr(j, 3, n) {
    if (sum + j <= n)
      ret += dp(i + 1, sum + j), ret %= mod;
  }
  return ret;
}
int main() {
  // freopen("calc.in","r",stdin);
  // freopen("calc.out","w",stdout);
  //__builtin_popcount()
  input cin >> n;
  memset(mem, -1, sizeof mem);
  cout << dp(1, 0) << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
ll n;
vector<ll> dp(2005, 0);
ll countWays() {

  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;

  for (int i = 4; i <= n; i++) {
    dp[i]++;
    for (int j = 3; j <= i - 3; j++) {
      dp[i] = (dp[i] + dp[j]) % mod;
    }
  }

  return dp[n] % mod;
}

int main() {
  cin >> n;
  cout << countWays() << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

ll n;
ll countWays() {
  ll DP[n + 1];
  vector<ll> dp(n + 1, 0);

  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;

  for (int i = 4; i <= n; i++) {
    dp[i]++;
    for (int j = 3; j <= i - 3; j++) {
      dp[i] = (dp[i] + dp[j]) % mod;
    }
  }

  return dp[n] % mod;
}

int main() {
  cin >> n;
  cout << countWays() << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long s, sm;
long long dp[2001][2001];
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> s;
  for (int i = 3; i <= s; i++)
    dp[1][i] = 1;
  for (int i = 2; i <= s / 3; i++) {
    for (int j = 3 * i; j <= s; j++) {
      for (int i1 = 3; i1 <= j; i1++) {
        dp[i][j] = dp[i][j] + dp[i - 1][j - i1];
        if (dp[i][j] >= (long long)(1e9 + 7)) {
          dp[i][j] -= (long long)(1e9 + 7);
        }
      }
    }
  }
  for (int i = 1; i <= s / 3; i++) {
    sm += dp[i][s];
    if (sm >= (long long)(1e9 + 7)) {
      sm -= (long long)(1e9 + 7);
    }
  }
  cout << sm;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long s, sm;
long long dp[2001][2001];
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> s;
  for (int i = 3; i <= s; i++)
    dp[1][i] = 1;
  for (int i = 2; i <= s / 3; i++) {
    for (int j = 3 * i; j <= s; j++) {
      for (int i1 = 3; i1 <= j; i1++) {
        dp[i][j] = dp[i][j] + dp[i - 1][j - i1];
        dp[i][j] %= (long long)(1e9 + 7);
      }
    }
  }
  for (int i = 1; i <= s / 3; i++) {
    sm += dp[i][s];
    sm %= (long long)(1e9 + 7);
  }
  cout << sm;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int, int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int s;
  cin >> s;
  vector<int> dp(s + 1);
  dp[0] = 1;
  int x = 0;
  for (int i = 1; i <= s; i++) {
    if (i >= 3) {
      x += dp[i - 3];
      x %= mod;
      dp[i] += x;
      dp[i] %= mod;
    }
  }
  cout << dp[s] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int, int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

uintmax_t combination(unsigned int n, unsigned int r) {
  if (r * 2 > n)
    r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor = 1;
  for (unsigned int i = 1; i <= r; ++i) {
    dividend *= (n - i + 1);
    divisor *= i;
  }
  return dividend / divisor;
}

int main() {
  int n;
  cin >> n;
  if (n <= 2) {
    cout << 0 << endl;
    return 0;
  }
  int m = n / 3;
  int a = n % 3;
  ll ans = 0;
  rep(i, m) {
    int mi = m - i;

    ans += combination(a + mi - 1, mi - 1);
    ans %= mod;
    a += 3;
  }
  cout << ans << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
// vector<vector<ll>> data(3, vector<ll>(4));
// vector<ll> data(N);
// str s = to_string(i);
// int i = c - '0'
// sort(data.begin(), data.end());
// reverse(data.begin(), data.end());
// data.erase(unique(data.begin(), data.end()), data.end());
// str.substr(n)//n番以降スライス
// str.substr(n,m)//n番以降m文字スライス
// str.erase(n)//n番以降削除
// str.erase(n,m)//n番以降m文字削除
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define FORD(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
#define PB push_back
#define MOD 1000000007
using namespace std;

int main() {
  ll N;
  cin >> N;

  vector<ll> data(N + 1);
  data.at(0) = 1;
  data.at(1) = 0;
  if (N >= 2)
    data.at(2) = 0;
  if (N >= 3) {
    FOR(i, 3, N + 1) {
      data.at(i) = data.at(i - 1) + data.at(i - 3);
      data.at(i) %= MOD;
    }
  }
  if (data.at(N) % MOD >= 0)
    data.at(N) = data.at(N) % MOD;
  else
    data.at(N) = data.at(N) % MOD + MOD;
  cout << data.at(N) << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
// vector<vector<ll>> data(3, vector<ll>(4));
// vector<ll> data(N);
// str s = to_string(i);
// int i = c - '0'
// sort(data.begin(), data.end());
// reverse(data.begin(), data.end());
// data.erase(unique(data.begin(), data.end()), data.end());
// str.substr(n)//n番以降スライス
// str.substr(n,m)//n番以降m文字スライス
// str.erase(n)//n番以降削除
// str.erase(n,m)//n番以降m文字削除
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define FORD(i, a, b) for (ll i = ll(a); i >= ll(b); i--)
#define PB push_back
#define MOD 1000000007
using namespace std;

int main() {
  ll N;
  ll s;
  cin >> N;

  vector<ll> data(N + 1);
  data.at(0) = 1;
  data.at(1) = 0;
  data.at(2) = 0;
  FOR(i, 3, N + 1) {
    data.at(i) = data.at(i - 1) + data.at(i - 3);
    data.at(i) %= MOD;
  }
  if (data.at(N) % MOD >= 0)
    data.at(N) = data.at(N) % MOD;
  else
    data.at(N) = data.at(N) % MOD + MOD;
  cout << data.at(N) << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int t;

ll S;

ll dp[2001];

ll solve(ll idx, ll prev_sum) {

  if (prev_sum == S) {
    return 1;
  }
  if (prev_sum > S) {
    return 0;
  }
  if (dp[prev_sum] != -1) {
    return dp[prev_sum];
  }
  //	cout << idx << ' ' <<prev_sum << endl;
  ll ans = 0;

  for (int i = 3; i <= S; i++) {
    ans += (solve(idx + 1, prev_sum + i) + MOD) % MOD;
  }

  return dp[prev_sum] = (ans + MOD) % MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

  cin >> S;
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0);
}


Error: TLE

Fixed submission:

/*----- || Hare Krishna || -----*/

/*  "WHY DO WE FALL, BRUCE?"  */

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#define ll long long
#define endl '\\n'
#define elif else if
#define pb push_back
#define pf push_front
#define PI 3.1415926535897932384
#define MOD 1000000007
using namespace std;

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int t;

ll S;

ll dp[2001][2001];

ll solve(ll idx, ll prev_sum) {
  //	cout << idx << ' ' << prev_sum << endl;
  if (prev_sum == S) {
    return 1;
  }
  if (prev_sum > S) {
    return 0;
  }
  if (dp[idx][prev_sum] != -1) {
    return dp[idx][prev_sum];
  }

  ll ans = 0;

  for (int i = 3; i <= S; i++) {
    ans += (solve(idx + 1, prev_sum + i) + MOD) % MOD;
  }

  return dp[idx][prev_sum] = (ans + MOD) % MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);

  cin >> S;
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0);
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

const int MOD = 1000000007;

int main() {
  ll s;
  cin >> s;
  ll dp[2001];               // oooo|ooooooo i番目の右に仕切り
  dp[0] = dp[1] = dp[2] = 0; // 数列なし
  dp[3] = dp[4] = dp[5] = 1; // 数列はひとつだけ(仕切りが右端)
  dp[6] = dp[3] + 1;
  // dp[7] = dp[4] + dp[3] = dp[4] + dp[6];
  // dp[8] = dp[5] + dp[4] + dp[3] = dp[5] + dp[7];
  // dp[n] = dp[n-3] + dp[n-1];
  if (s >= 7) {
    for (int i = 7; i <= s; i++) {
      dp[i] = dp[i - 3] + dp[i - 1];
      dp[i] %= MOD;
    }
  }

  cout << dp[s] << endl;
}

Error: 0

Fixed submission:

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

const int MOD = 1000000007;

int main() {
  ll s;
  cin >> s;
  ll dp[s + 1];              // oooo|ooooooo i番目の右に仕切り
  dp[0] = dp[1] = dp[2] = 0; // 数列なし
  dp[3] = dp[4] = dp[5] = 1; // 数列はひとつだけ(仕切りが右端)
  dp[6] = dp[3] + 1;
  // dp[7] = dp[4] + dp[3] = dp[4] + dp[6];
  // dp[8] = dp[5] + dp[4] + dp[3] = dp[5] + dp[7];
  // dp[n] = dp[n-3] + dp[n-1];
  if (s >= 7) {
    for (int i = 7; i <= s; i++) {
      dp[i] = dp[i - 3] + dp[i - 1];
      dp[i] %= MOD;
    }
  }

  cout << dp[s] << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(x) begin(x), end(x)
#define show(obj)                                                              \\
  {                                                                            \\
    for (auto x : obj)                                                         \\
      cout << x << ' ';                                                        \\
    cout << endl;                                                              \\
  }
#define line "----------"
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int inf = 1001001000;
const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;

int main() {
  int S;
  cin >> S;
  vector<ll> dp(S + 1, 0);
  dp[0] = 1;
  for (int i = 3; i <= S; ++i) {
    for (int j = 3; j <= i; ++j) {
      dp[i] += dp[i - j];
      dp[i] %= MOD;
    }
  }
  cout << dp[S] << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
#define all(x) begin(x), end(x)
#define show(obj)                                                              \\
  {                                                                            \\
    for (auto x : obj)                                                         \\
      cout << x << ' ';                                                        \\
    cout << endl;                                                              \\
  }
#define line "----------"
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int inf = 1001001000;
const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;

int main() {
  int S;
  cin >> S;
  vector<vector<ll>> dp(S + 1, vector<ll>(700, 0));
  ll ans = 0;
  for (int i = 3; i < 2000; ++i) {
    dp[i][0] = 1;
  }
  for (int i = 0; i < 2000; ++i) {
    for (int k = 3; k < 2000; ++k) {
      if (i + k <= 2000)
        dp[i + 1][k + i] += dp[i][k];
      dp[i + 1][k + i] %= MOD;
    }
  }
  cout << dp[S][S] << endl;
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long dp[2005];

long long done(int n) {
  if (n < 0) {
    return 0;
  }
  if (n == 0) {
    return 1;
  }
  if (dp[n] != -1)
    return dp[n];
  long long ans = 0;
  for (int i = 3; i <= n; i++) {
    ans += done(n - i);
  }
  dp[n] = (ans % m);
  return (ans % m);
}

int main() {
  int n;
  cin >> n;
  memset(dp, -1, sizeof(dp));
  cout << done(n) << endl;
}


Error: TLE

Fixed submission:

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

long long ans = 0;

void done(int n) {
  if (n < 0) {
    return;
  }
  if (n == 0) {
    ans = ((1 + ans) % m);
  }
  for (int i = 3; i <= 9; i++) {
    done(n - i);
  }
}

int main() {
  int n;
  cin >> n;
  ans = 0;
  done(n);
  cout << ans << endl;
}