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

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int S;
long long mod = 1000000007;
long long arr[2001];
int func(int x) {

  if (x == 3 || x == 4 || x == 5) {
    return 1;
  } else if (x < 3) {
    return 0;
  } else if (x == 6) {
    return 2;
  } else if (x == 7) {
    return 3;
  } /*
   else if(x == 8){
       return 4;
   }
   else if(x == 9){
       return 6;
   }
   else if(x == 10){
       return 9;
   }
   else if (x == 11){
       return 13;
   }
   else if (x == 12){
       return 18;
   }
   */
  long long ans = 0;
  /*
  for(int i = 3; i <= x-3; ++i){
      //ans += func(i)%mod * func(x-i)%mod;
      ans += func(i)%mod;
  }
  */
  // ans = func(x-1)%mod + func(x-3)%mod;
  ans = arr[x - 1] % mod + arr[x - 3] % mod;
  // ans *=2;
  // return ans+1;
  return ans % mod;
}

int main() {
  cin >> S;

  long long ans = 0;
  if (S <= 2) {
    cout << 0 << endl;
    return 0;
  }
  // ans  = func(S);

  /*
  for(int i = 3; i < S-3; ++i){

      ans += func(i)%mod * func(S-i)%mod;

  }
  */

  for (int i = 1; i <= S; ++i) {
    arr[i] = func(i);
  }
  cout << arr[S] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int S;
long long mod = 1000000007;
int func(int x) {

  if (x == 3 || x == 4 || x == 5) {
    return 1;
  } else if (x < 3) {
    return 0;
  } else if (x == 6) {
    return 2;
  } else if (x == 7) {
    return 3;
  } else if (x == 8) {
    return 4;
  } else if (x == 9) {
    return 6;
  } else if (x == 10) {
    return 9;
  } else if (x == 11) {
    return 13;
  } else if (x == 12) {
    return 18;
  }

  long long ans = 0;
  /*
  for(int i = 3; i <= x-3; ++i){
      //ans += func(i)%mod * func(x-i)%mod;
      ans += func(i)%mod;
  }
  */
  ans = func(x - 1) % mod + func(x - 3) % mod;

  // ans *=2;
  // return ans+1;
  return ans;
}

int main() {
  cin >> S;

  long long ans = 0;
  if (S <= 2) {
    cout << 0 << endl;
    return 0;
  }
  ans = func(S);
  cout << ans << endl;
  /*
  for(int i = 3; i < S-3; ++i){

      ans += func(i)%mod * func(S-i)%mod;

  }
  */

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

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <time.h>
#include <vector>
#define lli long long int
#define h 1000000007
#define s 2010
#define pf push_front
#define pb push_back
#define ub upper_bound
#define lb lowepr_bound
#define mp make_pair
#define pi 3.14159
using namespace std;
vector<lli> a(s, -1);
lli solve(lli sum) {
  lli i, cnt;
  if (sum == 0)
    return 1;
  else if (sum >= 3 && sum <= 5)
    return 1;
  else if (a[sum] != -1)
    return a[sum];
  else {
    cnt = 0;
    for (i = 3; i <= sum; i++) {
      if ((sum - i) >= 0)
        cnt = ((cnt % h) + (solve(sum - i) % h)) % h;
      else
        break;
    }
    a[sum] = cnt;
    return a[sum];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli i, n;
  cin >> n;
  cout << solve(n) << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <time.h>
#include <vector>
#define lli long long int
#define h 1000000007
#define s 10000
#define pf push_front
#define pb push_back
#define ub upper_bound
#define lb lowepr_bound
#define mp make_pair
#define pi 3.14159
using namespace std;
lli n, cnt = 0, flag = 0;
vector<lli> a;
void solve(lli sum) {
  lli i;
  if (sum == n) {
    cnt = ((cnt % h) + 1) % h;
    flag = 1;
    return;
  } else if (sum > n) {
    flag = 1;
    return;
  }
  for (i = 0; i < a.size(); i++) {
    solve(sum + a[i]);
    if (flag) {
      flag = 0;
      return;
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli i, sum = 0;
  cin >> n;
  for (i = 0; i < (n - 2); i++)
    a.pb(i + 3);
  solve(sum);
  cout << cnt << endl;
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

const int mod = 1e9 + 7;
long long int dp[2005];

int main() {
  int s;
  scanf("%d", &s);
  dp[0] = 1;
  dp[1] = dp[2] = 0;
  for (int a = 0; a <= s; a++) {
    for (int b = 3; b <= s; b++) {
      if (a + b <= s)
        (dp[a + b] += dp[a]) %= mod;
    }
  }
  printf("%lld ", dp[s]);
}


Error: WA

Fixed submission:

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

const int mod = 1e9 + 7;
long long int dp[2005];

int main() {
  int s;
  scanf("%d", &s);
  dp[0] = 1;
  dp[1] = dp[2] = 0;
  for (int a = 0; a <= s; a++) {
    for (int b = 3; b <= s; b++) {
      (dp[a + b] += dp[a]) %= mod;
    }
  }
  printf("%lld ", dp[s]);
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;

ll solve(ll a) {
  if (a == 0) {
    return 1;
  } else if (a == 1 || a == 2) {
    return 0;
  } else if (a >= 3 && a <= 5) {
    return 1;
  } else {
    ll b = 0;
    for (ll i = a - 3; i >= 0; i--) {
      b = (b + solve(i)) % mod;
    }
    return b;
  }
}

int main() {
  ll s;
  cin >> s;
  vector<ll> ans(s + 10);
  rep(i, s + 10) { ans[i] = 0; }
  ans[0] = 1;
  ans[1] = 0;
  ans[2] = 0;
  ans[3] = 1;
  ans[4] = 1;
  ans[5] = 1;
  for (ll i = 6; i <= s; i++) {
    for (ll j = i - 3; j >= 0; j--) {
      ans[i] = (ans[i] + ans[j]) % mod;
    }
  }
  cout << ans[s] << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const ll mod = 1e9 + 7;

ll solve(ll a) {
  if (a == 0) {
    return 1;
  } else if (a == 1 || a == 2) {
    return 0;
  } else if (a >= 3 && a <= 5) {
    return 1;
  } else {
    ll b = 0;
    for (ll i = a - 3; i >= 0; i--) {
      b = (b + solve(i)) % mod;
    }
    return b;
  }
}

int main() {
  ll s;
  cin >> s;
  vector<ll> ans(s + 1);
  rep(i, s + 1) { ans[i] = 0; }
  ans[0] = 1;
  ans[1] = 0;
  ans[2] = 0;
  ans[3] = 1;
  ans[4] = 1;
  ans[5] = 1;
  for (ll i = 6; i <= s; i++) {
    for (ll j = i - 3; j >= 0; j--) {
      ans[i] = (ans[i] + ans[j]) % mod;
    }
  }
  cout << ans[s] << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define REP(i, p, n) for (ll i = p; i < ll(n); ++i)
#define rep(i, n) REP(i, 0, n)

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

const ll mod = 1000000007;

const ll MAXS = 2001;
ll dp[MAXS];

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

  dp[0] = 1;

  for (ll i = 3; i <= S; ++i) {
    dp[i] += (i - 1 >= 0 ? dp[i - 1] : 0);
    dp[i] += (i - 3 >= 0 ? dp[i - 3] : 0);
    dp[i] %= mod;
  }

  cout << dp[S] << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

#define REP(i, p, n) for (ll i = p; i < ll(n); ++i)
#define rep(i, n) REP(i, 0, n)

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

const ll mod = 1000000007;

const ll MAXS = 2001;
ll dp[MAXS][MAXS];

ll S;

ll dfs(ll k, ll s) {
  if (S <= s) {
    return S == s ? 1 : 0;
  }
  if (dp[k][s] != -1) {
    return dp[k][s];
  }

  ll res = 0;

  for (ll ss = s + 3; ss <= S; ++ss) {
    res += dfs(k + 1, ss);
    res %= mod;
  }

  return dp[k][s] = res;
}

int main() {
  cin >> S;

  rep(i, S) {
    rep(j, S) { dp[i][j] = -1; }
  }

  const auto ans = dfs(0, 0);
  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
const int MOD = 1e9 + 7;
const int INF = 1e18;
void io(string s = "file") {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

int dp[2001];

int f(int s) {
  if (s < 0 || s == 1 || s == 2)
    return 0;
  if (s == 0)
    return 1;
  int &ans = dp[s];
  if (ans != -1)
    return ans;
  ans = 0;
  for (int j = 3; j <= s; j++) {
    ans += f(s - j);
    ans %= MOD;
  }
  return ans;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int S;
  cin >> S;
  memset(dp, -1, sizeof dp);
  cout << f(S);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
const int MOD = 1e9 + 7;
const int INF = 1e18;
void io(string s = "file") {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

int dp[2001];
int S;

int f(int s) {
  if (s < 0)
    return 0;
  if (s == 0)
    return 1;
  int &ans = dp[s];
  ans = 0;
  for (int j = 3; j <= s; j++) {
    ans += f(s - j);
    ans %= MOD;
  }
  return ans;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> S;
  memset(dp, -1, sizeof dp);
  cout << f(S);
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll dp[2001];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (ll i = 4; i <= n; i++) {
    dp[i] = 1;
    for (ll j = 3; j <= i - 3; j++) {
      dp[i] += dp[j];
      dp[i] %= MOD;
    }
  }
  cout << dp[n];
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
int main() {
  ll n;
  cin >> n;
  ll dp[n + 1];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = 0;
  dp[3] = 1;
  for (ll i = 4; i <= n; i++) {
    dp[i] = 1;
    for (ll j = 3; j <= i - 3; j++) {
      dp[i] += dp[j];
      dp[i] %= MOD;
    }
  }
  cout << dp[n];
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll int
int const MOD = 1e9 + 7;
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;
ll sum;
ll cache[700][2001];
ll dp(int i, int s) {
  if (s > sum)
    return 0;
  if (s == sum)
    return 1;
  ll &ans = cache[i][s];
  if (ans != -1)
    return ans;
  ans = 0;
  for (int j = 3; j <= sum - s; j++)
    ans += dp(i + 1, s + j), ans %= MOD;
  return ans % MOD;
}
int32_t main() {
  fastIO;
  memset(cache, -1, sizeof(cache));
  cin >> sum;
  ll ans = 0;
  for (int i = 3; i <= sum; i++)
    ans += dp(0, i), ans %= MOD;
  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll int
int const MOD = 1e9 + 7;
#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL)
using namespace std;
ll sum;
ll cache[700][2001];
ll dp(int i, int s) {
  if (s > sum)
    return 0;
  if (s == sum)
    return 1;
  ll &ans = cache[i][s];
  if (ans != -1)
    return ans;
  ans = 0;
  for (int j = 3; j <= sum; j++)
    ans += dp(i + 1, s + j), ans %= MOD;
  return ans % MOD;
}
int32_t main() {
  fastIO;
  memset(cache, -1, sizeof(cache));
  cin >> sum;
  ll ans = 0;
  for (int i = 3; i <= sum; i++)
    ans += dp(0, i), ans %= MOD;
  cout << ans;

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n;
ll d[2001];
ll mod = 1e9 + 7;

ll go(int x) {
  if (x == n) {
    return 1;
  }
  ll &ret = d[x];
  if (ret != -1)
    return ret;
  ret = 0;
  for (int i = 3; i <= 2000; i++) {
    if (x + i <= n) {
      ret += go(x + i);
      ret %= mod;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  cin >> n;

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

  cout << go(0) << '\\n';
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
ll n;
ll d[701][2001];
ll mod = 1e9 + 7;

ll go(int x, int y) {
  if (y == n) {
    return 1;
  }
  ll &ret = d[x][y];
  if (ret != -1)
    return ret;
  ret = 0;
  for (int i = 3; i <= 2000; i++) {
    if (y + i <= n) {
      ret += go(x + 1, y + i);
      ret %= mod;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  cin >> n;

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

  cout << go(0, 0) << '\\n';
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;
ll f[2006];
int main() {
  ios;
  f[0] = 1;
  for (int i = 3; i <= 2000; ++i)
    for (int j = 3; j <= i; ++j) {
      f[i] = (f[i] + f[i - j]) % mod;
    }
  int s;
  cin >> s;
  cout << f[s] << '\\n';
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int a[10001] = {1}, n;
unsigned long long ans;
void print(int t) {
  for (int i = 1; i <= t; i++)
    if (a[i] < 3)
      return;
  ans++;
  ans %= mod;
}
int search(int s, int t) {
  int i;
  for (int i = 1; i <= s; i++)
    if (i < n) {
      a[t] = i;
      s -= i;
      if (s == 0)
        print(t);
      else
        search(s, t + 1);
      s += i;
    }
}
int main() {
  cin >> n;
  if (n < 3) {
    cout << "0";
    return 0;
  }

  search(n, 1);
  ans++;
  cout << ans % mod;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const long long mod = 1e9 + 7;
long long dp[N] = {};
int main() {
  int n;
  cin >> n;
  if (n >= 3)
    fill(dp + 3, dp + n + 1, 1);
  for (int i = 4; i <= n; i++)
    for (int j = i - 3; j >= 0; j--)
      dp[i] = (dp[i] + dp[j]) % mod;
  cout << dp[n] << '\\n';
  return 0;
}

Error: 0

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F(i, a, n) for (int i = a; i < n; i++)
#define mod 1000000007
#define pb push_back
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int w = 1;
  // cin>>w;
  while (w--) {
    long long n;
    cin >> n;
    vector<ll> v(2005, 0);
    v[0] = 1;
    v[3] = 1;
    v[4] = 1;
    v[5] = 1;
    F(i, 6, n + 1) {
      F(j, 3, i + 1) {
        if (i - j >= 0)
          v[i] = (v[i] % mod + v[i - j] % mod) % mod;
      }
    }
    cout << v[n];
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F(i, a, n) for (int i = a; i < n; i++)
#define mod 1000000007
#define pb push_back
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int w = 1;
  // cin>>w;
  while (w--) {
    long long n;
    cin >> n;
    vector<ll> v(n + 1, 0);
    v[0] = 1;
    v[3] = 1;
    v[4] = 1;
    v[5] = 1;
    F(i, 6, n + 1) {
      F(j, 3, i + 1) {
        if (i - j >= 0)
          v[i] = (v[i] % mod + v[i - j] % mod) % mod;
      }
    }
    cout << v[n];
  }
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

const int mod = 1000000007;

int main() {
  int s;
  cin >> s;
  vector<ll> dp(s + 1);

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


Error: WA

Fixed submission:

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

const int mod = 1000000007;

int main() {
  int s;
  cin >> s;
  vector<ll> dp(s + 1);

  dp[0] = 1;
  dp[1] = 0;
  dp[2] = 0;
  for (int i = 3; i <= s; i++) {
    dp[i] = dp[i - 1] + dp[i - 3];
    dp[i] %= mod;
  }
  cout << dp[s];
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll n;
ll mod = 1000000007;
ll dp[30000];
ll finds(ll in, ll sum) {
  if (sum > n)
    return 0;
  if (sum == n)
    return 1;
  if (dp[sum] != -1)
    return dp[sum];
  ll ans = 0;
  for (int i = 3; i <= (n - sum); i++) {
    if (sum + i <= n)
      ans += finds(in + 1, sum + i);
    if (ans != 0)
      ans %= mod;
  }
  return dp[sum] = ans;
}
int main() {
  // IOS;
  // ll t;cin>>t;while(t--)
  {
    memset(dp, -1, sizeof dp);
    ll a, b, c, d, i, j, k, l, m, temp = 0, f = 0, cnt = 0;
    cin >> n;
    cout << finds(0, 0) << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
ll n;
ll mod = 1000000007;
ll dp[1000][30000];
ll finds(ll in, ll sum) {
  if (sum > n)
    return 0;
  if (sum == n)
    return 1;
  if (dp[in][sum] != -1)
    return dp[in][sum];
  ll ans = 0;
  for (int i = 3; i <= (n - sum) + 1; i++) {
    if (sum + i <= n)
      ans += finds(in + 1, sum + i);
    if (ans != 0)
      ans %= mod;
  }
  return dp[in][sum] = ans;
}
int main() {
  // IOS;
  // ll t;cin>>t;while(t--)
  {
    memset(dp, -1, sizeof dp);
    ll a, b, c, d, i, j, k, l, m, temp = 0, f = 0, cnt = 0;
    cin >> n;
    cout << finds(0, 0) << endl;
  }
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

//////https://atcoder.jp/contests/abc178/tasks/abc178_d
#include <bits/stdc++.h>

using namespace std;

const int MO = 1e9 + 7;
const int MAXN = 2e3 + 2;
long long ans[MAXN];

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

  // 初始化ans
  ans[0] = 1;

  for (int i = 3; i <= s; i++) {
    for (int j = 3; j <= i; j++) {
      ans[i] = (ans[i] + ans[i - j]) % MO;
    }
  }

  cout << ans[s] << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

//////https://atcoder.jp/contests/abc178/tasks/abc178_d
#include <bits/stdc++.h>
using namespace std;

const int MO = 1e9 + 7;
int s;
long long ans = 0;
vector<int> seq;

void dfs(int sum) {
  if (s == sum) {
    ans = (ans + 1) % MO;
#if 0
        cout<<"{";
        for (int i=0; i<seq.size(); i++) {
            cout<<seq[i]<<",";
        }
        cout<<"}\\n";
#endif
    return;
  } else if (sum > s) {
    return;
  }
  for (int i = 3; i <= s - sum; i++) {
    seq.push_back(i);
    dfs(sum + i);
    seq.pop_back();
  }
}

int main() {
  cin >> s;

  dfs(0);
  cout << ans << "\\n";

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 999999999
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
ll cnt = 0, ans = 0;
const int MAX = 510000;

ll move(ll n) {
  ll a[n + 10];
  a[0] = 1;
  a[1] = 0;
  a[2] = 0;
  a[3] = 1;

  for (int i = 4; i <= n; i++) {
    a[i] = (a[i - 1] + a[i - 3]) % MOD;
  }
  return a[n];
}

int main() {
  ll n;
  cin >> n;
  ans = move(n);
  cout << ans % MOD << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 999999999
#define rep(i, n) for (int i = 0; i < n; i++)
const ll MOD = 1000000007;
ll cnt = 0, ans = 0;
const int MAX = 510000;

ll move(ll n) {
  ll a[n + 1];
  a[0] = 1;
  a[1] = 0;
  a[2] = 0;
  a[3] = 1;

  for (int i = 4; i <= n; i++) {
    a[i] = (a[i - 1] + a[i - 3]) % MOD;
  }
  return a[n];
}

int main() {
  ll n;
  cin >> n;
  ans = move(n);
  cout << ans % MOD << endl;
}