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

#include <bits/stdc++.h>

const int INF = 1e9;
const int MOD = 998244353;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> vpii;
  REP(i, k) {
    ll a, b;
    cin >> a >> b;
    vpii.push_back({a, b});
  }
  vector<ll> memo(n + 1, 0);
  memo[1] = 1;
  vector<vector<int>> start(n + 1);
  vector<vector<int>> stop(n + 1);
  set<int> si;
  ll a = 0;
  FOR(i, 1, n + 1) {
    if (!start[i].empty()) {
      REP(j, start[i].size()) {
        a += memo[start[i][j]];
        a %= MOD;
      }
    }
    memo[i] += a;
    memo[i] %= MOD;
    REP(j, k) {
      if (i + vpii[j].first <= n)
        start[i + vpii[j].first].push_back(i);
      if (i + vpii[j].second <= n)
        stop[i + vpii[j].second].push_back(i);
    }
    if (!stop[i].empty()) {
      REP(j, stop[i].size()) {
        a = a - memo[stop[i][j]] + MOD;
        a %= MOD;
      }
    }
  }
  cout << memo[n] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

const int INF = 1e9;
const int MOD = 998244353;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<pair<ll, ll>> vpii;
  REP(i, k) {
    ll a, b;
    cin >> a >> b;
    vpii.push_back({a, b});
  }
  vector<ll> memo(n + 1, 0);
  memo[1] = 1;
  vector<vector<int>> start(n + 1);
  vector<vector<int>> stop(n + 1);
  set<int> si;
  FOR(i, 1, n + 1) {
    if (!start[i].empty()) {
      REP(j, start[i].size()) { si.insert(start[i][j]); }
    }
    for (auto x : si) {
      memo[i] += memo[x];
      memo[i] %= MOD;
    }
    REP(j, k) {
      if (i + vpii[j].first <= n)
        start[i + vpii[j].first].push_back(i);
      if (i + vpii[j].second <= n)
        stop[i + vpii[j].second].push_back(i);
    }
    if (!stop[i].empty()) {
      REP(j, stop[i].size()) { si.erase(stop[i][j]); }
    }
  }
  cout << memo[n] << endl;
}
Problem p02549 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;

int main() {
  ll n, k, ans = 0, l, r;
  set<ll> st;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  ll dp[n + 1] = {};
  dp[0] = 1;
  dp[1] = -1;
  rep(i, k) {
    cin >> l >> r;
    r++;
    v[i].first = l, v[i].second = r;
  }
  for (int i = 0; i < n; ++i) {
    if (i > 0)
      (dp[i] += dp[i - 1]) %= mod;
    for (int j = 0; j < k; ++j) {
      l = v[j].first, r = v[j].second;
      if (i + l < n)
        (dp[i + l] += dp[i]) %= mod;
      if (i + r < n)
        (dp[i + r] -= dp[i] - mod) %= mod;
      // if (i + r < n && dp[i + r] < 0) dp[i + r]+= mod;
    }
  }

  // rep(i, n - 1)(dp[i + 1] += dp[i]) %= mod;

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

Error: TLE

Fixed submission:

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

int main() {

  int n, k;
  cin >> n >> k;

  vector<int> range(n + 1, 0);
  vector<pair<int, int>> v;

  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    v.push_back({x, y});
    range[x]++;
    range[y + 1]--;
  }

  for (int i = 1; i <= n; i++) {
    range[i] = range[i - 1] + range[i];
  }

  vector<int> poss;

  for (int i = 1; i <= n; i++) {
    if (range[i] >= 1) {
      poss.push_back(i);
    }
  }

  vector<int> dp(n + 1, 0);
  for (int i = 0; i < poss.size(); i++) {
    dp[poss[i]] = 1;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < poss.size(); j++) {
      if (poss[j] <= i) {
        dp[i] = (dp[i] % mod + dp[i - poss[j]] % mod) % mod;
      }
    }
  }

  cout << dp[n - 1] << endl;

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

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

const int MAX = 2000;
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() {
  COMinit();
  int S;
  cin >> S;
  int L = S / 3, N = S % 3;
  ll ans = 0;
  while (L > 0) {
    ans = (ans + COM(L - 1 + N, N)) % MOD; // cout<< ans;
    L--;
    N += 3;
  }
  cout << ans;
}


Error: WA

Fixed submission:

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

const int MAX = 670;
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() {
  COMinit();
  int S;
  cin >> S;
  int L = S / 3, N = S % 3;
  ll ans = 0;
  while (L > 0) {
    ans = (ans + COM(L - 1 + N, N)) % MOD; // cout<< ans;
    L--;
    N += 3;
  }
  cout << ans;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

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

int64_t mod = 1000000007;

int64_t f(int n, vector<int64_t> &a) {
  if (a.at(n) != -1)
    return a.at(n);
  else {
    a.at(n) = (f(n - 1, a) + f(n - 3, a));
    a.at(n) %= mod;
    return a.at(n);
  }
}

int main() {
  int s;
  cin >> s;
  vector<int64_t> a(s + 1, -1);
  if (s < 3) {
    cout << 0 << endl;
    return 0;
  }
  a.at(0) = 0, a.at(1) = 0, a.at(2) = 0;
  a.at(3) = 1;
  int64_t ans;
  ans = f(s, a);
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int64_t mod = 1000000007;

int64_t f(int n, vector<int64_t> &a) {
  if (a.at(n) != -1)
    return a.at(n);
  else {
    a.at(n) = (f(n - 1, a) + f(n - 3, a));
    a.at(n) %= mod;
    return a.at(n);
  }
}

int main() {
  int s;
  cin >> s;
  vector<int64_t> a(s + 1, -1);
  if (s < 3) {
    cout << 0 << endl;
    return 0;
  }
  a.at(0) = 0, a.at(1) = 0, a.at(2) = 0;
  a.at(3) = 1, a.at(4) = 1, a.at(5) = 1;
  int64_t ans;
  ans = f(s, a);
  cout << ans << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

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

vector<ll> dp;
ll ans = 0;
ll mod = 1e9 + 7;
int solve(int v) {
  // cout << v << endl;
  if (dp[v] > 1)
    return dp[v];

  for (int i = 3; v - i >= 0; i++)
    dp[v] = (dp[v] + solve(v - i)) % mod;

  return dp[v];
}

int main() {
  int n;
  cin >> n;
  if (n < 3)
    return cout << 0 << endl, 0;

  dp.resize(n + 1, 1);
  dp[0] = 0, dp[1] = 0, dp[2] = 0, dp[3] = 1;

  cout << solve(n) % mod << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define all(a) a.begin(), a.end()
#define len(a) (int)a.size()

using namespace std;

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

vector<ll> dp;
ll ans = 0;
ll mod = 1e9 + 7;
int solve(int v) {
  // cout << v << endl;
  if (dp[v] > 1)
    return dp[v];

  for (int i = 3; v - i >= 0; i++)
    dp[v] = (dp[v] + solve(v - i)) % mod;

  return dp[v];
}

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

  dp.resize(n + 1, 1);
  dp[0] = 0, dp[1] = 0, dp[2] = 0, dp[3] = 1;

  cout << solve(n) % mod << endl;
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\\n'

ll dp[2001];

ll DFS(int i, int sum) {
  if (sum == 0)
    return 1;
  if (sum <= 2)
    return 0;
  if (dp[sum] != -1)
    return dp[sum];

  ll ans = 0;
  for (int x = 3; x <= sum; ++x) {
    ans += DFS(i + 1, sum - x);
    ans %= mod;
  }
  return dp[sum] = ans;
}

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

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


Error: TLE

Fixed submission:

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

using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\\n'

int dp[700][2001];

ll DFS(int i, int sum) {
  if (sum == 0)
    return 1;
  if (sum <= 2)
    return 0;
  if (dp[i][sum] != -1)
    return dp[i][sum];

  ll ans = 0;
  for (int x = 3; x <= sum; ++x) {
    ans += DFS(i + 1, sum - x);
    ans %= mod;
  }
  return dp[i][sum] = ans;
}

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

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



#include <iostream>
using namespace std;
long long int dp[2005];
long long int mod(long long int x) {
  return (x % 1000000007 + 1000000007) % 1000000007;
}
int main() {
  long long int s;
  cin >> s;

  for (int i = 0; i < s + 2; i++) {
    dp[i] = 0LL;
  }
  dp[0] = 1LL;
  dp[1] = 0LL, dp[2] = 0LL;
  dp[3] = 1LL;
  dp[4] = 1LL;
  dp[5] = 1LL;
  for (long long int i = 6; i <= s; i++) {
    for (long long int j = 3; j <= i; j++) {
      if (i - j >= 0 && i - j <= s && i >= 0 && i <= s)
        dp[i] = mod(mod(dp[i]) + mod(dp[i - j]));
    }
  }
  cout << mod(dp[s]) << endl;

  return 0;
}


Error: 0

Fixed submission:



#include <iostream>
using namespace std;

long long int mod(long long int x) {
  return (x % 1000000007 + 1000000007) % 1000000007;
}
int main() {
  long long int s;
  cin >> s;
  long long int dp[s + 2];
  for (int i = 0; i < s + 2; i++) {
    dp[i] = 0LL;
  }
  dp[0] = 1LL;
  dp[1] = 0LL, dp[2] = 0LL;
  dp[3] = 1LL;
  dp[4] = 1LL;
  dp[5] = 1LL;
  for (long long int i = 6; i <= s; i++) {
    for (long long int j = 3; j <= i; j++) {
      if (i - j >= 0 && i - j <= s && i >= 0 && i <= s)
        dp[i] = mod(mod(dp[i]) + mod(dp[i - j]));
    }
  }
  cout << mod(dp[s]) << endl;

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

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

ll INF = (ll)1e20;
int iINF = (int)1e20;
ll mod = (ll)1e9 + 7;

signed main() {
  ll n;
  cin >> n;
  vector<ll> dp(n + 100, 0);
  if (n < 3) {
    cout << 0;
    return 0;
  }
  dp[3] = 1;
  for (int i = 4; i <= n; ++i) {
    dp[i] = 1;
    for (int j = 3; j < i; ++j) {
      if (i - j >= 3) {
        dp[i] += dp[j];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n];
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

ll INF = (ll)1e20;
int iINF = (int)1e20;
ll mod = (ll)1e9 + 7;

signed main() {
  ll n;
  cin >> n;
  ll dp[n + 1];
  fill(&dp[0], &dp[0] + n + 1, 0);
  dp[3] = 1;
  for (int i = 4; i <= n; ++i) {
    dp[i] = 1;
    for (int j = 3; j < i; ++j) {
      if (i - j >= 3) {
        dp[i] += dp[j];
        dp[i] %= mod;
      }
    }
  }
  cout << dp[n];
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MOD = 1000000007;

int main() {
  ll s;
  cin >> s;
  vector<ll> A;
  A.push_back(0);
  A.push_back(0);
  A.push_back(0);
  A.push_back(1);
  if (s < 4) {
    cout << A[s] << endl;
  } else {
    FOR(i, 4, s + 1) { A.push_back((A[i - 3] + A[i - 1]) % MOD); }
    cout << A[s] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll MOD = 1000000007;

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

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

#define sync                                                                   \\
  {                                                                            \\
    ios_base ::sync_with_stdio(false);                                         \\
    cin.tie(NULL);                                                             \\
    cout.tie(NULL);                                                            \\
  }
#define ll long long int
#define mod 1000000007

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

  ll dp[s + 1];

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

  else if (s == 3) {
    cout << 1;
    return;
  }

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

  dp[3] = 1;

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

int main() {
  sync;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}


Error: 0

Fixed submission:

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

#define sync                                                                   \\
  {                                                                            \\
    ios_base ::sync_with_stdio(false);                                         \\
    cin.tie(NULL);                                                             \\
    cout.tie(NULL);                                                            \\
  }
#define ll long long int
#define mod 1000000007

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

  ll dp[s + 1];

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

  dp[3] = 1;

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

int main() {
  sync;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
    cout << "\\n";
  }
  return 0;
}
Problem p02555 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <climits>

using namespace std;

#define debug(x, y)                                                            \\
  cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i, a, b) for (i = a; i < b; i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(), (x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

lld dp[2001][2001];

lld solve(lld n, lld l) {
  if (n < 0 || n == 1 || n == 2 || l < 0)
    return 0;
  if ((l == 0 && n != 0) || (n == 0 && l != 0))
    return dp[n][l] = 0;
  if (n == 0 && l == 0) {
    return dp[n][l] = 1;
  }
  lld c = 0;
  if (dp[n][l] != -1)
    return dp[n][l];
  c += solve(n - 1, l);
  c %= MOD;
  c += solve(n - 3, l - 1);
  c %= MOD;
  return dp[n][l] = c;
}

int main() {
  fast;
  cin.tie(0);
  lld n;
  cin >> n;
  if (n == 1 || n == 2)
    cout << "0" << endl;
  else {
    memset(dp, -1, sizeof(dp));
    lld cnt = 0;
    for (lld i = 1; i <= (n / 3) + 1; i++) {
      cnt += solve(n, i);
      cnt %= MOD;
    }
    cout << cnt << endl;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <climits>

using namespace std;

#define debug(x, y)                                                            \\
  cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast ios_base::sync_with_stdio(false)
#define fie(i, a, b) for (i = a; i < b; i++)
#define MOD 1000000007
#define mod 998244353
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ll long long
#define lld long long int
#define ALL(x) (x).begin(), (x).end()

typedef vector<lld> vi;
typedef vector<vector<lld>> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<pair<lld, lld>> vpi;
typedef long long LL;

lld dp[2001][2001];

lld solve(lld n, lld l) {
  if (n < 0 || n == 1 || n == 2 || l < 0)
    return 0;
  if ((l == 0 && n != 0) || (n == 0 && l != 0))
    return dp[n][l] = 0;
  if (n == 0 && l == 0) {
    return dp[n][l] = 1;
  }
  lld c = 0;
  if (dp[n][l] != -1)
    return dp[n][l];
  for (lld i = 3; i <= n; i++) {
    c += solve(n - i, l - 1);
    c %= MOD;
  }
  return dp[n][l] = c;
}

int main() {
  fast;
  cin.tie(0);
  lld n;
  cin >> n;
  if (n == 1 || n == 2)
    cout << "0" << endl;
  else {
    memset(dp, -1, sizeof(dp));
    lld cnt = 0;
    for (lld i = 1; i <= (n / 3) + 1; i++) {
      cnt += solve(n, i);
      cnt %= MOD;
    }
    cout << cnt << endl;
  }
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const int MAXN = 2000 + 5;
vector<vector<ll>> dp(MAXN, vector<ll>(MAXN, 0));

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (int k = 1; k < MAXN; k++) {
    dp[1][k] = k;
  }
  for (int s = 1; s < MAXN; s++) {
    dp[s][1] = 1;
  }
  for (int s = 2; s < MAXN; s++) {
    for (int k = 2; k < MAXN; k++) {
      dp[s][k] = (dp[s][k - 1] + dp[s - 1][k]) % MOD;
    }
  }
  int S;
  cin >> S;
  ll ans = 0;
  for (int i = 1; i < S; i++) {
    ans += dp[max(S - 3 * i, 0)][i];
    if (S - 3 * i == 0)
      ans += 1;
    // cout << i << " " << S - 3*i << " = " << dp[max(S - 3*i, 0)][i] << endl;
    ans %= MOD;
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define db(a) cout << fixed << #a << " = " << a << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll MOD = 1e9 + 7;
const int MAXN = 20 + 5;
vector<vector<ll>> dp(MAXN, vector<ll>(MAXN, 0));

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (int k = 1; k < MAXN; k++) {
    dp[1][k] = k;
  }
  for (int s = 1; s < MAXN; s++) {
    dp[s][1] = 1;
  }
  for (int s = 2; s < MAXN; s++) {
    for (int k = 2; k < MAXN; k++) {
      dp[s][k] = (dp[s][k - 1] + dp[s - 1][k]) % MOD;
    }
  }
  int S;
  cin >> S;
  ll ans = 0;
  for (int i = 1; i < S; i++) {
    ans += dp[max(S - 3 * i, 0)][i];
    if (S - 3 * i == 0)
      ans += 1;
    // cout << i << " " << S - 3*i << " = " << dp[max(S - 3*i, 0)][i] << endl;
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02555 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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

// 177

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main() {
  int s;
  ll ans = 0;
  cin >> s;
  vector<vector<ll>> v(s, vector<ll>(s + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v.at(i).at(0) = 1;
  }
  for (int i = 1; i < v.size(); i++) {
    for (int j = 1; j < i + 1; j++) {
      v.at(i).at(j) = (v.at(i - 1).at(j - 1) + v.at(i - 1).at(j)) % NUM;
    }
  }
  for (int i = 1; s >= 3 * i; i++) {
    ans += v.at(s - i * 2 - 1).at(i - 1);
    ans %= NUM;
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

// 177

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main() {
  int s;
  ll ans = 0;
  cin >> s;
  vector<vector<ll>> v(s - 2, vector<ll>(s - 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v.at(i).at(0) = 1;
  }
  for (int i = 1; i < v.size(); i++) {
    for (int j = 1; j < i + 1; j++) {
      v.at(i).at(j) = (v.at(i - 1).at(j - 1) + v.at(i - 1).at(j)) % NUM;
    }
  }
  for (int i = 1; s >= 3 * i; i++) {
    ans += v.at(s - i * 2 - 1).at(i - 1);
    ans %= NUM;
  }
  cout << ans << endl;
  return 0;
}