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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int s;
  cin >> s;
  if (s >= 0 && s <= 2) {
    cout << 0 << endl;
    return 0;
  }
  if (s >= 3 && s <= 5) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> dp(s + 1, 0);
  rep(i, 3) {
    dp[i] = 0;
    dp[i + 3] = 1;
  }
  rep(i, s + 1) {
    if (0 <= i && i <= 5)
      continue;
    dp[i] = (dp[i - 1] + dp[i - 3]) % inf;
  }
  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)

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

int main() {
  int s;
  cin >> s;
  vector<ll> dp(s + 1, 0);
  rep(i, 3) {
    dp[i] = 0;
    dp[i + 3] = 1;
  }
  rep(i, s + 1) {
    if (0 <= i && i <= 5)
      continue;
    dp[i] = (dp[i - 1] + dp[i - 3]) % inf;
  }
  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 main() {
  ll int s;
  cin >> s;
  ll int dp[s];
  dp[0] = 0, dp[1] = 0, dp[2] = 1;
  for (ll int i = 3; i < s; i++) {
    dp[i] = (dp[i - 1] + dp[i - 3]) % 1000000007;
  }
  cout << dp[s - 1];
  return 0;
}

Error: WA

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007

lli n;
vector<lli> dp;

lli bhardo(lli i) {
  if (dp[i] != -1)
    return dp[i];
  lli ans = 0;
  for (lli j = 3; j <= i; j++) {
    ans = (ans + bhardo(i - j)) % mod;
  }
  dp[i] = ans;
  return dp[i];
}

int main() {
  cin >> n;
  if (n < 3) {
    cout << 0;
    return 0;
  }
  dp = vector<lli>(n + 1, -1);
  if (n <= 5) {
    cout << 1;
    return 0;
  }
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  cout << bhardo(n);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007

lli n;
vector<lli> dp;

lli bhardo(lli i) {
  if (dp[i] != -1)
    return dp[i];
  lli ans = 0;
  for (lli j = 3; j <= i; j++) {
    ans = (ans + bhardo(i - j)) % mod;
  }
  dp[i] = ans;
  return dp[i];
}

int main() {
  cin >> n;
  if (n < 3) {
    cout << 0;
    return 0;
  }
  dp = vector<lli>(n + 1, -1);
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  dp[4] = 1;
  dp[5] = 1;
  // lli ans=0;
  // for(lli i=3;i<=n;i++)
  // {
  //     ans=ans+dp[n-i];
  // }
  cout << bhardo(n);
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;

#define REP(a, b, c) for (ll a = b; a < (c); a++)
#define PER(a, b, c) for (ll a = b; a >= (c); a--)

inline ll ii() {
  ll x;
  cin >> x;
  return x;
}
inline string is() {
  string x;
  cin >> x;
  return x;
}
inline ld id() {
  ld x;
  cin >> x;
  return x;
}
inline void oi(ll x) { cout << x; }
inline void od(ld x) { cout << fixed << setprecision(10) << x; }
inline void os(string x) { cout << x; }
inline void oe() { cout << endl; }
inline void oie(ll x) {
  oi(x);
  oe();
}
inline void ode(ld x) {
  od(x);
  oe();
}
inline void ose(string x) {
  os(x);
  oe();
}
inline void maxin(ll &a, ll b) { a = max(a, b); }
inline void minin(ll &a, ll b) { a = min(a, b); }

ll m[1123][2123];
ll mod = 1e9 + 7;

int main() {
  ll S = ii();
  ll ret = 0;
  m[0][0] = 1;
  REP(i, 0, 667) {
    ll s = 0;
    REP(k, 0, S - 3 + 1) {
      s += m[i][k];
      if (k + 3 == S) {
        ret += s;
        ret %= mod;
      } else {
        m[i + 1][k + 3] += s;
        m[i + 1][k + 3] %= mod;
      }
    }
  }
  oie(ret);

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;

#define REP(a, b, c) for (ll a = b; a < (c); a++)
#define PER(a, b, c) for (ll a = b; a >= (c); a--)

inline ll ii() {
  ll x;
  cin >> x;
  return x;
}
inline string is() {
  string x;
  cin >> x;
  return x;
}
inline ld id() {
  ld x;
  cin >> x;
  return x;
}
inline void oi(ll x) { cout << x; }
inline void od(ld x) { cout << fixed << setprecision(10) << x; }
inline void os(string x) { cout << x; }
inline void oe() { cout << endl; }
inline void oie(ll x) {
  oi(x);
  oe();
}
inline void ode(ld x) {
  od(x);
  oe();
}
inline void ose(string x) {
  os(x);
  oe();
}
inline void maxin(ll &a, ll b) { a = max(a, b); }
inline void minin(ll &a, ll b) { a = min(a, b); }

ll m[1123][2123];
ll mod = 1e9 + 7;

int main() {
  ll S = ii();
  ll ret = 0;
  m[0][0] = 1;
  REP(i, 0, 667) {
    REP(k, 0, S) {
      if (m[i][k] == 0)
        continue;
      for (ll j = 3; k + j <= S; j++) {
        if (k + j == S) {
          ret += m[i][k];
          ret %= mod;
        } else {
          m[i + 1][k + j] += m[i][k];
          m[i + 1][k + j] %= mod;
        }
      }
    }
  }
  oie(ret);

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

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back

#define limit (int)(1e6 + 5)
#define mod (long long int)(1e9 + 7)

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

lli dp[2001];
int s;

lli fa(int ps) {
  // cout << in << " " << ps << "\\n";
  if (ps == 0) {
    return 1;
  }

  if (ps < 3) {
    // dp[ps] = 0;
    return 0;
  }

  if (dp[ps] != -1) {
    return dp[ps];
  }

  dp[ps] = 0;

  for (int i = 3; i <= ps; ++i) {
    dp[ps] += fa(ps - i);
    dp[ps] %= mod;
  }

  return dp[ps];
}

int main() {
  // ios_base::sync_with_stdio(false);cin.tie(NULL);
  cin >> s;

  if (s < 3) {
    cout << 0;
    return 0;
  }

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

  fa(s);

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back

#define limit (int)(1e6 + 5)
#define mod (long long int)(1e9 + 7)

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

lli dp[2000][667];
int s;

lli fa(int in, int ps) {
  // cout << in << " " << ps << "\\n";
  if (ps == s) {
    return 1;
  }

  if (s - ps < 3) {
    dp[ps][s] = 0;
    return 0;
  }

  if (dp[ps][in] != -1) {
    return dp[ps][in];
  }

  dp[ps][in] = 0;

  for (int i = 3; i <= s; ++i) {
    if (i + ps > s) {
      break;
    }

    dp[ps][in] += fa(in + 1, ps + i);
    dp[ps][in] %= mod;
  }

  return dp[ps][in];
}

int main() {
  // ios_base::sync_with_stdio(false);cin.tie(NULL);
  cin >> s;

  for (int i = 0; i <= s; ++i) {
    for (int j = 0; j <= s / 3; ++j) {
      dp[i][j] = -1;
    }
  }

  fa(0, 0);

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

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

#define fi first
#define se second
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " is " << x << "\\n";

using ll = long long;
using ii = pair<ll, ll>;

const int S = 2005;
const int N = 670;
const int MOD = 1e9 + 7;

ll dp[N][S];
int main() {
  int s;
  scanf("%d", &s);
  dp[0][0] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 3; j <= s; j++) {
      // dp[i][j] = dp[i - 1][j - 3] + dp[i - 1][j - 4] + ... + dp[i - 1][0]
      // dp[i][j - 1] = dp[i - 1][j - 4] + dp[i - 1][j - 5] + ... + dp[i - 1][0]
      // dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 3];

      dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 3];
      if (dp[i][j] >= MOD)
        dp[i][j] -= MOD;

      // for(int k = 3; k <= j; k++) {
      //   dp[i][j] += dp[i - 1][j - k];
      //   if(dp[i][j] >= MOD) dp[i][j] -= MOD;
      // }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += dp[i][s];
    if (ans >= MOD)
      ans -= MOD;
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

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

#define fi first
#define se second
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " is " << x << "\\n";

using ll = long long;
using ii = pair<ll, ll>;

const int S = 2005;
const int N = 670;
const int MOD = 1e9 + 7;

ll dp[N][S];
int main() {
  int s;
  scanf("%d", &s);
  dp[0][0] = 1;
  for (int i = 1; i < N; i++) {
    for (int j = 3; j <= s; j++) {
      for (int k = 3; k <= j; k++) {
        dp[i][j] += dp[i - 1][j - k];
        if (dp[i][j] >= MOD)
          dp[i][j] -= MOD;
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += dp[i][s];
    if (ans >= MOD)
      ans -= MOD;
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<long> dp(N + 1, 0);
  for (int i = 3; i <= N; i++) {
    // int l=i/2;
    for (int j = 3; j <= i - 3; j++) {
      dp.at(i) += dp.at(i - j);
      dp.at(i) %= 1000000007;
    }
    dp.at(i)++;
  }
  cout << dp.at(N) << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<long> dp(N + 1, 0);
  dp.at(1) = 0;
  dp.at(2) = 0;
  dp.at(3) = 1;
  dp.at(4) = 1;
  dp.at(5) = 1;
  for (int i = 6; i <= N; i++) {
    // int l=i/2;
    for (int j = 3; j <= i - 3; j++) {
      dp.at(i) += dp.at(i - j);
      dp.at(i) %= 1000000007;
    }
    dp.at(i)++;
  }
  cout << dp.at(N) << 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 repl(i, l, r) for (int i = l; i < r; i++)
using namespace std;
using ll = long long;
static const ll MOD = 1e9 + 7;
static const int inf = 1e9 + 10;
static const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

const int Max = 2005;
int A[Max];

int solve(int n) {
  if (A[n] != -1)
    return A[n];
  if (n == 0)
    return A[n] = 1;
  if (n < 3)
    return A[n] = 0;
  if (n == 3)
    return A[n] = 1;
  A[n] = solve(n - 3) + solve(n - 1);
  A[n] %= MOD;
  return A[n];
}

int main() {
  rep(i, Max) A[i] = -1;
  int n;
  cin >> n;
  cout << solve(n) << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

static const ll Max = 2005;

ll DP[Max];

void init() {
  for (ll i = 0; i < Max; i++)
    DP[i] = -1;
}
ll Inf = 1e9 + 7;

ll factorial(int n) {
  if (DP[n] != -1)
    return DP[n];
  if (n == 0)
    return DP[n] = 1;
  if (n == 1)
    return DP[n] = 1;
  DP[n] = factorial(n - 1) * (ll)n;
  return DP[n];
}

int main() {
  init();
  int s;
  cin >> s;
  ll ans = 0;

  for (int i = 1; i <= (s / 3); i++) {
    ans += factorial(s - 2 * i - 1) / (factorial(s - 3 * i) * factorial(i - 1));
    ans %= Inf;
  }
  cout << ans << endl;
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\\n'
#define sz(a) (int)(a.size())
#define all(a) begin(a), end(a)
#define deb(a) cout << #a << ": " << a << ENDL
#define fore(i, a, b) for (int i(a), ThkMk(b); i < ThkMk; ++i)
#define _                                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

const int MAX = 2005;

lli dp[MAX];

lli n;

lli MOD = 1e9 + 7;

lli solve(lli v) {
  if (v < 0)
    return 0;
  if (v == 0)
    return 1;
  lli &ans = dp[v];
  if (ans != -1)
    return ans;
  ans = 0;
  fore(i, 3, v + 1) ans = (ans + solve(v - i)) % MOD;
  return ans;
}

int main() {
  _ fore(j, 0, MAX) dp[j] = -1;
  cin >> n;
  cout << solve(n) << ENDL;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\\n'
#define sz(a) (int)(a.size())
#define all(a) begin(a), end(a)
#define deb(a) cout << #a << ": " << a << ENDL
#define fore(i, a, b) for (int i(a), ThkMk(b); i < ThkMk; ++i)
#define _                                                                      \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

const int MAX = 2005;

lli dp[MAX][MAX];

lli n;

lli MOD = 1e9 + 7;

lli solve(lli u, lli v) {
  if (v < 0)
    return 0;
  if (v == 0)
    return 1;
  lli &ans = dp[u][v];
  if (ans != -1)
    return ans;
  ans = 0;
  fore(i, 3, v + 1) ans = (ans + solve(u + 1, v - i)) % MOD;
  return ans;
}

int main() {
  _ fore(i, 0, MAX) fore(j, 0, MAX) dp[i][j] = -1;
  cin >> n;
  cout << solve(0, n) << ENDL;
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
  ll S;
  cin >> S;
  vector<ll> vec(2001);
  vec[0] = 0;
  vec[1] = 0;
  vec[2] = 0;
  vec[3] = 1;
  vec[4] = 1;
  vec[5] = 1;
  for (int i = 6; i <= S; ++i) {
    ll tmp = 1;
    for (int j = 3; j <= i - 3; ++j) {
      tmp += vec[j];
      tmp %= mod;
    }
    vec[i] = tmp;
  }

  cout << vec[S] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
  ll S;
  cin >> S;
  vector<ll> vec(S + 1);
  vec[0] = 0;
  vec[1] = 0;
  vec[2] = 0;
  vec[3] = 1;
  vec[4] = 1;
  vec[5] = 1;
  for (int i = 6; i <= S; ++i) {
    ll tmp = 1;
    for (int j = 3; j <= i - 3; ++j) {
      tmp += vec[j];
      tmp %= mod;
    }
    vec[i] = tmp;
  }

  cout << vec[S] << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

vector<ll> ans(2001, 0);

int main() {
  ans.at(0) = 1;
  ll s;
  cin >> s;
  for (int i = 3; i <= s; i++) {
    ll x = 0;
    for (int j = 0; j <= i - 3; j++) {
      x = (x + ans.at(j)) % mod;
    }
    ans.at(i) = x;
  }
  cout << ans.at(s) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

vector<ll> ans(2001, INF);

ll f(ll x) {
  if (ans.at(x) != INF)
    return ans.at(x);
  if (x < 3) {
    ans.at(x) = 0;
    return 0;
  }
  ll ret = 0;
  for (int i = 3; i <= x; i++) {
    ret += f(x - i);
  }
  return ret;
}

int main() {
  ans.at(0) = 1;
  ll s;
  cin >> s;
  cout << f(s) << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

int countSequence(int sum) {
  ll dp[2001];
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= sum; i++) {
    ll total = 0;
    for (int j = 3; j <= i; j++) {
      total = (total + dp[i - j]) % mod;
    }
    dp[i] = total;
  }
  return dp[sum];
}
int main() {
  int s;
  cin >> s;
  int size = s - 3 + 1;
  int arr[size];
  int start = 3;
  for (int i = 0; i < size; i++) {
    arr[i] = start;
    start++;
  }

  int ans = countSequence(s);
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int dp[2001][2001];
long long mod = 1000000007;
int factorial(int n) {
  if (n <= 1)
    return 1;
  long long fact = 1;
  for (int i = 2; i <= n; i++) {
    fact = (fact * (long long)i);
    fact %= mod;
  }
  return fact;
}
int countSequence(int arr[], int n, int sum, vector<int> output) {
  if (sum == 0) {
    int len = output.size();
    map<int, int> m;
    int ans = factorial(len);
    for (int i = 0; i < output.size(); i++)
      m[output[i]]++;
    long long mult = 1;
    for (auto it : m) {
      int a = factorial(it.second);
      mult = (mult * a) % mod;
    }
    ans = (ans / mult) % mod;
    return ans;
  }
  if (n == 0 and sum > 0)
    return 0;
  if (dp[n][sum] != -1)
    return dp[n][sum];
  int ans;
  if (arr[0] > sum)
    ans = countSequence(arr + 1, n - 1, sum, output);
  else {
    int c1 = countSequence(arr + 1, n - 1, sum, output);
    vector<int> out = output;
    out.push_back(arr[0]);
    int c2 = countSequence(arr, n, sum - arr[0], out);
    ans = c1 + c2;
  }
  ans %= mod;
  dp[n][sum] = ans;
  return ans;
}
int main() {
  int s;
  cin >> s;
  int size = s - 3 + 1;
  int arr[size];
  int start = 3;
  for (int i = 0; i < size; i++) {
    arr[i] = start;
    start++;
  }

  vector<int> output;
  memset(dp, -1, sizeof(dp));
  int ans = countSequence(arr, size, s, output);
  cout << ans;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 2, Mod = 1e9 + 7;
long long int dp[N];
int s;
long long calc(long long sum) {
  // cout<<1;
  if (sum == s)
    return 1;
  if (sum > s)
    return 0;
  long long &ret = dp[sum];
  if (ret != -1)
    return ret;
  ret = 0;
  bool z = 0, n = 0;
  for (int i = 3; i <= s; i++) {

    ret += calc(sum + i) % Mod;
    ret %= Mod;
  }
  return ret %= Mod;
}
int main() {
  cin >> s;
  memset(dp, -1, sizeof dp);
  cout << calc(0);
  // cout<<2;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e2 + 2, Mod = 1e9 + 7;
long long int dp[N];
int s;
long long calc(long long sum) {
  // cout<<1;
  if (sum == s)
    return 1;
  if (sum > s)
    return 0;
  long long &ret = dp[sum];
  if (ret != -1)
    return ret;
  ret = 0;
  bool z = 0, n = 0;
  for (int i = 3; i <= s; i++) {

    ret += calc(sum + i) % Mod;
    ret %= Mod;
  }
  return ret %= Mod;
}
int main() {
  cin >> s;
  memset(dp, -1, sizeof dp);
  cout << calc(0);
  // cout<<2;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> dp(n + 1);
  if (n < 3) {
    cout << "0";
    return 0;
  }
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= n; i++) {
    for (int j = 3; j <= i; j++) {
      dp[i] = (dp[i] + dp[i - j]) % mod;
    }
  }
  cout << dp[n];
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<ll> dp(n + 1);
  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (int i = 4; i <= n; i++) {
    for (int j = 3; j <= i; j++) {
      dp[i] = (dp[i] + dp[i - j]) % mod;
    }
  }
  cout << dp[n];
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

#define INF 1e9
#define PI 3.141592653589793238
#define N 1000000010
#define mod 1000000007
#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)
typedef long long ll;

int main() {
  ll sum;
  cin >> sum;
  ll ary[3000];
  for (int i = 0; i <= sum; i++)
    ary[i] = 0;
  ary[0] = 1;
  ary[1] = 0;
  ary[2] = 0;
  ary[3] = 1;
  ary[4] = 1;
  ary[5] = 1;
  for (int i = 6; i <= sum; i++) {
    for (int j = i - 3; j >= 0; j--) {
      ary[i] += ary[j];
      ary[i] %= mod;
    }
  }

  ll ans = ary[sum];
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

#define INF 1e9
#define PI 3.141592653589793238
#define N 1000000010
#define mod 1000000007
#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)
typedef long long ll;

int main() {
  ll sum;
  cin >> sum;
  ll ary[sum];
  REP(i, 0, sum + 1) ary[i] = 0;
  ary[0] = 1;
  ary[3] = 1;
  ary[4] = 1;
  ary[5] = 1;
  for (int i = 6; i <= sum; i++) {
    for (int j = i - 3; j >= 0; j--) {
      ary[i] += ary[j];
      ary[i] %= mod;
    }
  }

  ll ans = ary[sum];
  cout << ans << endl;

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
  ll res = 1;
  for (ll i = 0; i < y; i++)
    res = res * x % mod;
  return res;
}

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

  if (s < 3) {
    cout << 0 << endl;
    return 0;
  }

  vector<ll> dp(s + 1, 0);
  dp[0] = 1;
  for (int i = 3; i <= s; i++)
    dp[i] = (dp[i - 1] + dp[i - 3]) % mod;
  cout << dp[s] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
  ll res = 1;
  for (ll i = 0; i < y; i++)
    res = res * x % mod;
  return res;
}

ll combination(int n, int k) {
  if (k == 0 || n == k)
    return 1;
  return combination(n - 1, k) + combination(n - 1, k - 1);
}

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

  if (s < 3) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  for (int i = 0; i < s / 3; i++) {
    int n = i + 1;
    int x = s - 3 * n;
    ans = (ans + combination(x + n - 1, x)) % mod;
  }
  cout << ans % mod << endl;
  return 0;
}