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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\\n"
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
ll mod = 1e9 + 7;
const double pi = acos(-1.0);

ll c[2001][2001];

void combina() {
  for (int i = 0; i <= 2000; i++)
    for (int j = 0; j <= i; j++) {
      if (j == i || j == 0)
        c[i][j] = 1;
      else
        c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
      c[i][j] %= mod;
    }
  // return c[i][j];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed;
  cout.precision(12);
  ll n;
  cin >> n;
  combina();
  ll r = 1, an = 0;
  while ((n - 2 * r - 1) >= 0) {
    ll x = n - 2 * r - 1;
    an = (an + c[x][r - 1]) % mod;
    r++;
  }
  cout << an << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\\n"
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
ll mod = 1e9 + 7;
const double pi = acos(-1.0);

ll fa[1000001];
ll inv[1000001];

ll modex(ll a, ll b) {
  if (b <= 0) {
    return 1;
  }
  if (b % 2 == 0) {
    ll x = modex(a, b / 2);
    return ((x * x) % mod);
  } else
    return ((a % mod * modex(a, b - 1)) % mod);
}
ll fact() {
  fa[0] = 1;
  for (int i = 1; i <= 3000; i++) {
    fa[i] = (fa[i - 1] * i) % mod;
  }
}

ll invfact() {
  inv[0] = 1;
  for (int i = 1; i <= 3000; i++)
    inv[i] = (inv[i - 1] * modex(i, mod - 2)) % mod;
}

ll ncr(ll n, ll r) {
  ll ans = (fa[n] * inv[n - r]) % mod;
  ans = (ans * inv[r]) % mod;
  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed;
  cout.precision(12);
  ll n;
  cin >> n;
  fact();
  invfact();
  // for(ll i=1;i<=2000;i++){
  // cout<<ncr(0, 0)<<endl;
  ll r = 1, x = (n - 2 * r - 1), an = 0;
  while (x >= (r - 1) && x >= 0 && (r - 1) >= 0) {
    an = (an + ncr(x, r - 1)) % mod;
    r++;
    x = (n - 2 * r - 1);
  }
  cout << an << endl;
  //}
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve() {
  long long s;
  cin >> s;

  vector<long long> dp(s + 1, 0LL);

  int i, j;

  long long hell = 1e9 + 7;

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

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

  for (i = 6; i <= s; i++) {
    for (j = i - 3; j >= 0; j--)
      dp[i] = (dp[i] + dp[j]) % hell;

    dp[i] = (dp[i] + 1LL) % hell;
  }
  cout << dp[s] << endl;
}

int main() {
  int t = 1;
  // cin>>t;

  while (t--) {
    solve();
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define mp make_pair
#define ll long long
#define pb push_back

void solve() {
  long long s;
  cin >> s;

  vector<long long> dp(s + 1, 0LL);

  int i, j;

  long long hell = 1e9 + 7;

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

  for (i = 6; i <= s; i++) {
    for (j = i - 3; j >= 0; j--)
      dp[i] = (dp[i] + dp[j]) % hell;

    dp[i] = (dp[i] + 1LL) % hell;
  }
  cout << dp[s] << endl;
}

int main() {
  int t = 1;
  // cin>>t;

  while (t--) {
    solve();
  }
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#define ll long long
using namespace std;
int f[2005][2005];
const ll mod = 1e9 + 7;
#define R register
int main() {
  // long long n;
  R int i, j, k, n, ans = 0;
  scanf("%d", &n);
  f[0][0] = 1;
  for (i = 0; i <= n / 3; ++i) { // 最多这么多轮
    for (j = i * 3; j <= n; ++j) {
      for (k = 3; k <= n - j; ++k)
        f[i + 1][j + k] += f[i][j], f[i + 1][j + k] > mod
                                        ? f[i + 1][j + k] -= mod
                                        : f[i + 1][j + k] ^= 0;
    }
  }
  for (i = 1; i <= n / 3; ++i)
    ans += f[i][n], ans %= mod;
  printf("%d\\n", ans);
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <algorithm>
#include <cstdio>
#define ll long long
using namespace std;
int f[2005][2005];
const ll mod = 1e9 + 7;
#define R register
int main() {
  // long long n;
  R int i, j, k, n, ans = 0;
  scanf("%lld", &n);
  f[0][0] = 1;
  for (i = 0; i <= n / 3; ++i) { // 最多这么多轮
    for (j = i * 3; j <= n; ++j) {
      for (k = 3; k <= n - j; ++k)
        f[i + 1][j + k] += f[i][j], f[i + 1][j + k] > mod
                                        ? f[i + 1][j + k] -= mod
                                        : f[i + 1][j + k] ^= 0;
    }
  }
  for (i = 1; i <= n / 3; ++i)
    ans += f[i][n], ans %= mod;
  printf("%lld\\n", ans);
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

const long long mod = (long long)1e9 + 7;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

// const long long mod = (long long)1e9 + 7;
int main() {
  long long s;
  cin >> s;

  long long dp[2005];

  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= s; ++i) {
    dp[i] = 1;
    for (int j = 3; j <= i; j++) {
      if (i - j >= 3) {
        dp[i] = (dp[i] + dp[j]) % mod;
      }
    }
  }
  cout << dp[s] << endl;

  return 0;
}

Error: 0

Fixed submission:

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

const long long mod = (long long)1e9 + 7;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}

// const long long mod = (long long)1e9 + 7;
int main() {
  long long s;
  cin >> s;

  long long dp[s + 1];

  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= s; ++i) {
    dp[i] = 1;
    for (int j = 3; j <= i; j++) {
      if (i - j >= 3) {
        dp[i] = (dp[i] + dp[j]) % mod;
      }
    }
  }
  cout << dp[s] << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 2010;
const int M = 1000000007;

int n, m, gr;
ll ans, s;
ll dp[maxn][maxn]; // 分为 i 组 ， 和为 j 的方案数
ll fac[maxn];

ll ksm(ll i, ll po) {
  i %= M;
  ll res = 1;
  while (po) {
    if (po & 1)
      res = res * i % M;
    po >>= 1;
    i = i * i % M;
  }
  return res;
}

ll inv(ll a) { return ksm(a, M - 2); }

ll c(ll N, ll K) {
  if (N < K)
    return 0;
  if (N < 0 || K < 0)
    return 0;
  return 1ll * fac[N] * inv(fac[K]) % M * inv(fac[N - K]) % M;
}

ll read() {
  ll s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}

int main() {
  fac[0] = 1ll;
  for (int i = 1; i <= 2001; i++)
    fac[i] = 1LL * fac[i - 1] * i % M;

  ans = 0;
  // printf("%lld\\n",c(3,1));
  s = read();
  if (s < 3)
    printf("0\\n");
  else {
    gr = s / 3LL;

    for (int i = 1; i <= gr; i++) {
      m = s - 3ll * i;
      //			printf("%lld\\n",c(m+i-1ll,i-1ll));
      ans = (ans + c(m + i - 1ll, i - 1ll)) % M;
    }
    printf("%d\\n", (ans + M) % M);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;

const int maxn = 2010;
const int M = 1000000007;

int n;
ll ans;
ll dp[maxn][maxn]; // 分为 i 组 ， 和为 j 的方案数

ll read() {
  ll s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}

int main() {
  n = read();
  if (n < 3)
    printf("0\\n");
  else {
    dp[0][0] = 1ll;
    for (int i = 1; i <= n / 3; ++i) {
      for (int j = 3; j <= n; ++j) {
        for (int k = 3; k <= j; ++k) {
          dp[i][j] = (dp[i][j] + dp[i - 1][j - k]) % M;
        }
      }
    }
    for (int i = 1; i <= n / 3; ++i) {
      ans = (ans + dp[i][n]) % M;
    }
    printf("%lld\\n", ans);
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define COUT(x) cout << (x) << "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define REP(i, n) for (int i = 0; i < n; i++)
#define YES(x) cout << (x ? "YES" : "NO") << "\\n"
#define Yes(x) cout << (x ? "Yes" : "No") << "\\n"
#define dump(x) cout << #x << " = " << (x) << "\\n"
#define endl "\\n"
using G = vector<vector<int>>;
using M = map<int, int>;
using P = pair<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct {
  int to;
  int cost;
};
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 INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

vector<int> dp(2000);

int main() {
  IOS;
  int s;
  cin >> s;

  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    for (int j = 3; j <= s; j++) {
      if (i < j)
        break;

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

  COUT(dp[s]);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define COUT(x) cout << (x) << "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define REP(i, n) for (int i = 0; i < n; i++)
#define YES(x) cout << (x ? "YES" : "NO") << "\\n"
#define Yes(x) cout << (x ? "Yes" : "No") << "\\n"
#define dump(x) cout << #x << " = " << (x) << "\\n"
#define endl "\\n"
using G = vector<vector<int>>;
using M = map<int, int>;
using P = pair<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct {
  int to;
  int cost;
};
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 INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
  IOS;
  int s;
  cin >> s;
  vector<int> dp(s);

  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    for (int j = 3; j <= s; j++) {
      if (i < j)
        break;

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

  COUT(dp[s]);
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
const int mod = 1e9 + 7;
#define all(x) x.begin(), x.end()
#define endl '\\n'
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
int dp[2010];
int solve(int n) {
  if (n == 0)
    return 1;
  if (n == 1 and n == 2)
    return 0;
  if (n >= 3 and n <= 5)
    return 1;
  if (dp[n] != -1)
    return dp[n];
  int ans = 0;
  for (int i = 3; i <= n; i++) {
    if (n - i >= 0) {
      int temp = (solve(n - i)) % mod;
      ans = (ans + temp) % mod;
    }
  }
  return dp[n] = ans;
}
int32_t main() {
  IOS;
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  cout << solve(n) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
const int mod = 1e9 + 7;
#define all(x) x.begin(), x.end()
#define endl '\\n'
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
int dp[2010];
int solve(int n) {
  if (n == 0)
    return 1;
  if (n == 1 and n == 2)
    return 0;
  if (n >= 3 and n <= 5)
    return 1;
  if (dp[n] != -1)
    return dp[n];
  int ans = 0;
  for (int i = 3; i <= n; i++) {
    if (n - i >= 0) {
      int temp = (solve(n - i)) % mod;
      ans = (ans + temp) % mod;
    }
  }
  return ans;
}
int32_t main() {
  IOS;
  int n;
  cin >> n;
  memset(dp, -1, sizeof dp);
  cout << solve(n) << endl;
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int MOD = 1000000007;
const int N = 700;

long long dp[2001];

void solve() {
  int s;
  cin >> s;

  memset(dp, -1, sizeof(dp));

  function<long long(int)> f = [&](int sum) -> long long {
    if (sum < 0)
      return 0;
    if (dp[sum] != -1)
      return dp[sum];
    if (sum == 0)
      return 1;
    long long ans = 0;
    for (int i = 3; i <= sum; ++i) {
      ans += f(sum - i);
      ans %= MOD;
    }
    return dp[sum] = ans;
  };

  cout << f(s) << '\\n';
}

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


Error: TLE

Fixed submission:

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

const int MOD = 1000000007;
const int N = 700;

long long dp[N][2001];

void solve() {
  int s;
  cin >> s;

  memset(dp, -1, sizeof(dp));

  function<long long(int, int)> f = [&](int i, int sum) -> long long {
    if (sum > s)
      return 0;
    if (dp[i][sum] != -1)
      return dp[i][sum];
    if (sum == s)
      return 1;
    long long ret = 0;
    for (int k = 3; k <= s - sum; ++k) {
      ret += f(i + 1, sum + k);
      ret %= MOD;
    }
    return dp[i][sum] = ret;
  };

  cout << f(0, 0) << '\\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long
#define mtv(kit) cout << #kit << " - " << kit << "\\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i, a, b) for (i = a; i < b; i++)
#define pii pair<ll, ll>
#define all(x) x.begin(), x.end()
#define nl "\\n"
#define ump unordered_map

ll a[2002], mod = 1e9 + 7;
ll s;

ll f(ll su) {
  if (su < 0)
    return 0;
  if (su == 0)
    return 1;
  if (a[su] != -1) {
    return a[su];
  }
  ll ans = 0;
  for (ll i = 3; i <= su; i++) {
    ans += f(su - i);
    ans %= mod;
  }
  return a[su] = ans;
}
void doit() {
  cin >> s;
  memset(a, -1, sizeof(a));
  cout << f(s) << nl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin >> t;
  for (ll i = 1; i <= t; i++) {
    doit();
  }
}


Error: TLE

Fixed submission:

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

#define ll long long
#define mtv(kit) cout << #kit << " - " << kit << "\\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i, a, b) for (i = a; i < b; i++)
#define pii pair<ll, ll>
#define all(x) x.begin(), x.end()
#define nl "\\n"
#define ump unordered_map

ll a[900][2002], mod = 1e9 + 7;
ll s;

ll f(ll in, ll su) {
  if (su < 0)
    return 0;
  if (su == 0)
    return 1;
  if (a[in][su] != -1) {
    return a[in][su];
  }
  ll ans = 0;
  for (ll i = 3; i <= min(s, su); i++) {
    ans += f(in + 1, su - i);
    ans %= mod;
  }
  return a[in][su] = ans;
}
void doit() {
  cin >> s;
  memset(a, -1, sizeof(a));
  cout << f(0, s) << nl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t = 1;
  // cin >> t;
  for (ll i = 1; i <= t; i++) {
    doit();
  }
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

long calc(long n, vector<long> &dp, long mod) {
  if (n < 3)
    return 0;
  if (dp[n] != 0)
    return dp[n];
  for (int i = 3; i <= n; i++) {

    if (n != i)
      dp[n] += calc(n - i, dp, mod);
    else
      dp[n]++;
    dp[n] %= mod;
  }
  dp[n] %= mod;

  return dp[n];
}

int main() {
  long s;
  cin >> s;
  long const mod = 1e9 + 7;
  vector<long> dp(s + 1);
  if (s >= 3)
    dp[3] = 1;

  cout << calc(s, dp, mod) << endl;
}

Error: 0

Fixed submission:

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

long calc(long n, vector<long> &dp, long mod) {
  if (n < 3)
    return 0;
  if (dp[n] != 0)
    return dp[n];
  for (int i = 3; i <= n; i++) {

    if (n != i)
      dp[n] += calc(n - i, dp, mod);
    else
      dp[n]++;
    dp[n] %= mod;
  }
  dp[n] %= mod;

  return dp[n];
}

int main() {
  long s;
  cin >> s;
  long const mod = 1e9 + 7;
  vector<long> dp(s + 1);
  dp[3] = 1;

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

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

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


Error: 0

Fixed submission:

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

int main() {
  ll s = 0;
  cin >> s;
  vector<ll> dp(s + 1, 0);
  dp[3] = 1;
  for (int i = 4; i <= s; i++)
    dp[i] = (dp[i - 1] + dp[i - 3]) % 1000000007;
  cout << dp[s] << endl;
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int mod = 1e9 + 7;
  int n;
  cin >> n;
  long long int dp[n + 7];
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  dp[6] = 2;
  for (int i = 7; i <= n; i++)
    dp[i] = (dp[i - 3] * 2 + dp[i - 4] + dp[i - 5]) % mod;
  cout << dp[n];
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int mod = 1e9 + 7;
  int n;
  cin >> n;
  long long int dp[n + 1];
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  dp[6] = 2;
  for (int i = 7; i <= n; i++)
    dp[i] = (dp[i - 3] * 2 + dp[i - 4] + dp[i - 5]) % mod;
  cout << dp[n];
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <math.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int S;
  cin >> S;
  long long temp = 1;
  if (S < 3) {
    cout << 0 << endl;
    return (0);
  }
  if (S <= 5) {
    cout << 1 << endl;
    return (0);
  }
  COMinit();
  for (int i = 1; i < S / 3; i++) {
    temp += COM((S - 2 * i - 3), i);
    temp = temp % 1000000007;
  }
  cout << temp << endl;
}

Error: TLE

Fixed submission:

#include <math.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int S;
  cin >> S;
  long long temp = 1;
  if (S < 3) {
    cout << 0 << endl;
    return (0);
  }
  if (S <= 5) {
    cout << 1 << endl;
    return (0);
  }
  for (int i = 1; i < S / 3; i++) {
    COMinit();
    temp += COM((S - 2 * i - 3), i);
    temp = temp % 1000000007;
  }
  cout << temp << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9 + 7;
int dp[2050];
int main() {
  int s;
  cin >> s;
  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    dp[i] = dp[i - 1] + dp[i - 3];
    dp[i] %= MOD;
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9 + 7;
ll dp[1000];
int main() {
  int s;
  cin >> s;
  dp[0] = 1;
  for (int i = 3; i <= s; i++) {
    dp[i] = dp[i - 1] + dp[i - 3];
    dp[i] %= MOD;
  }

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

#include <bits/stdc++.h>

using namespace std;

#define ll long long int

ll mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll s;
  cin >> s;
  ll dp[s + 2], cum[s + 2];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  cum[0] = 0;
  cum[1] = 0;
  cum[2] = 0;
  cum[3] = 1;
  for (int i = 4; i <= s; i++) {
    dp[i] = (cum[i - 3] + 1) % mod;
    cum[i] = (cum[i - 1] + dp[i]) % mod;
  }

  cout << dp[s] % mod << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long int

ll mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll s;
  cin >> s;
  ll dp[s + 1], cum[s + 1];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  cum[0] = 0;
  cum[1] = 0;
  cum[2] = 0;
  cum[3] = 1;
  for (int i = 4; i <= s; i++) {
    dp[i] = (cum[i - 3] + 1) % mod;
    cum[i] = (cum[i - 1] + dp[i]) % mod;
  }

  cout << dp[s] % mod << endl;
  return 0;
}