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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

vector<int> poloc;
vector<int> poloc_odd;

void make_poloc() {
  int n = 1;
  while (1) {
    int a = n * (n + 1) * (n + 2) / 6;
    if (a > 1000000)
      break;

    poloc.push_back(a);
    if (a % 2 == 1)
      poloc_odd.push_back(a);
    n++;
  }
}

int main() {
  make_poloc();

  int n;
  int dp[1000001];
  for (int i = 0; i <= 1000000; i++) {
    dp[i] = 1000000;
  }
  dp[0] = 0;
  for (int i = 0; i < poloc.size(); i++) {
    for (int j = 0; j <= 1000000; j++) {
      if (j + poloc[i] <= 1000000)
        dp[j + poloc[i]] = min(dp[j + poloc[i]], dp[j] + 1);
    }
  }
  int dpp[1000001] = {0};
  for (int i = 0; i <= 1000000; i++) {
    dpp[i] = 1000000;
  }
  dpp[0] = 0;
  for (int i = 0; i < poloc_odd.size(); i++) {
    for (int j = 0; j <= 1000000; j++) {
      if (j + poloc_odd[i] <= 1000000)
        dpp[j + poloc_odd[i]] = min(dpp[j + poloc_odd[i]], dpp[j] + 1);
    }
  }

  while (cin >> n) {
    if (n == 0)
      break;
    cout << dp[n] << " " << dpp[n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

vector<int> poloc;
vector<int> poloc_odd;

void make_poloc() {
  int n = 1;
  while (1) {
    int a = n * (n + 1) * (n + 2) / 6;
    if (a > 1000000)
      break;

    poloc.push_back(a);
    if (a % 2 == 1)
      poloc_odd.push_back(a);
    n++;
  }
}
int search1(int n, int i, int depth) {
  if (n == 0)
    return depth;
  else if (n < 0 || i < 0)
    return 1000000;
  else
    return min(
        min(search1(n - poloc[i], i - 1, depth + 1), search1(n, i - 1, depth)),
        search1(n - poloc[i], i, depth + 1));
}
int search2(int n, int i, int depth) {
  if (n == 0)
    return depth;
  else if (n < 0 || i < 0)
    return 1000000;
  else
    return min(min(search2(n - poloc_odd[i], i - 1, depth + 1),
                   search2(n, i - 1, depth)),
               search2(n - poloc_odd[i], i, depth + 1));
}

int main() {
  make_poloc();
  int n;

  while (cin >> n) {
    if (n == 0)
      break;
    cout << search1(n, static_cast<int>(poloc.size() - 1), 0) << " "
         << search2(n, static_cast<int>(poloc_odd.size() - 1), 0) << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

#define MAX 1000000
using ll = long long;

int main() {
  vector<ll> v;
  vector<ll> odd_v;

  for (ll i = 1; i < MAX; ++i) {
    ll num = i * (i + 1) * (i + 2) / 6;
    v.push_back(num);
    if (num & 1)
      odd_v.push_back(num);
  }

  int dp[MAX];
  int odd_dp[MAX];
  fill(dp, dp + MAX, INT_MAX);
  fill(odd_dp, odd_dp + MAX, INT_MAX);
  dp[0] = 0;
  odd_dp[0] = 0;

  for (int i = 0; i < MAX; ++i) {
    for (int j = 0; j < v.size(); ++j) {
      if (i - v[j] >= 0)
        dp[i] = min(dp[i - v[j]] + 1, dp[i]);
      else
        break;
    }

    for (int j = 0; j < odd_v.size(); ++j) {
      if (i - odd_v[j] >= 0)
        odd_dp[i] = min(odd_dp[i - odd_v[j]] + 1, odd_dp[i]);
      else
        break;
    }
  }

  while (true) {
    int n;
    cin >> n;
    if (!n)
      break;

    cout << dp[n] << ' ' << odd_dp[n] << endl;
  }

  return EXIT_SUCCESS;
}


Error: TLE

Fixed submission:

#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

#define MAX 1000000
using ll = long long;

int main() {
  vector<ll> v;
  vector<ll> odd_v;

  for (ll i = 1; i <= MAX; ++i) {
    ll num = i * (i + 1) * (i + 2) / 6;
    v.push_back(num);
    if (num & 1)
      odd_v.push_back(num);
  }

  while (true) {
    int n;
    cin >> n;
    if (!n)
      break;

    vector<int> dp(n + 1, INT_MAX);
    vector<int> odd_dp(n + 1, INT_MAX);
    dp[0] = 0;
    odd_dp[0] = 0;

    for (int i = 0; i <= n; ++i) {
      for (int j = 0; j < v.size(); ++j) {
        if (n < v[j])
          break;
        if (i - v[j] >= 0) {
          dp[i] = min(dp[i - v[j]] + 1, dp[i]);
        }
      }

      for (int j = 0; j < odd_v.size(); ++j) {
        if (n < odd_v[j])
          break;
        if (i - odd_v[j] >= 0) {
          odd_dp[i] = min(odd_dp[i - odd_v[j]] + 1, odd_dp[i]);
        }
      }
    }
    cout << dp[n] << ' ' << odd_dp[n] << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <iterator>

using namespace std;

int N;

int L[200];
int M[200];
int M_max;
int dp[1000001];

void init() {
  for (int i = 1; i <= 200; i++) {
    L[i - 1] = (i * (i + 1) * (i + 2)) / 6;
  }

  int j = 0;
  for (int i = 0; i < 200 && L[i] <= 1000000; i++) {
    if (L[i] % 2 == 1) {
      M[j++] = L[i];
    }
  }
  M_max = j;

  for (int i = 0; i <= 1000000; i++) {
    dp[i] = 10000000;
  }
  dp[0] = 0;
  for (int i = 1; i <= 1000000; i++) {
    for (int j = 0; j < M_max && M[j] <= i; j++) {
      dp[i] = min(dp[i], dp[i - M[j]] + 1);
    }
  }
}

int f(int nth, int s) {
  int r = N - s;
  int start = distance(L, upper_bound(L, L + 200, r)) - 1;

  int m = 100;
  for (int i = start; i >= 0 && r <= (5 - nth) * L[i]; i--) {
    if (r == L[i]) {
      return nth + 1;
    }

    m = min(m, f(nth + 1, s + L[i]));
  }

  return m;
}

void solve() { printf("%d %d\\n", f(0, 0), dp[N]); }

int main() {
  init();
  while (true) {
    scanf("%d", &N);
    if (!N) {
      break;
    }
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iterator>

using namespace std;

int N;

int L[200];
int M[200];
int M_max;

void init() {
  for (int i = 1; i <= 200; i++) {
    L[i - 1] = (i * (i + 1) * (i + 2)) / 6;
  }

  int j = 0;
  for (int i = 0; i < 200; i++) {
    if (L[i] % 2 == 1) {
      M[j++] = L[i];
    }
  }
  M_max = j;
}

int f(int nth, int s) {
  int r = N - s;
  int start = distance(L, upper_bound(L, L + 200, r)) - 1;

  int m = 100;
  for (int i = start; i >= 0 && r <= (5 - nth) * L[i]; i--) {
    if (r == L[i]) {
      return nth + 1;
    }

    m = min(m, f(nth + 1, s + L[i]));
  }

  return m;
}

int g(int nth, int s) {
  int r = N - s;
  int start = distance(M, upper_bound(M, M + M_max, r)) - 1;

  int m = 100;
  for (int i = start; i >= 0; i--) {
    if (r == M[i]) {
      return nth + 1;
    }

    m = min(m, g(nth + 1, s + M[i]));
  }

  return m;
}

void solve() { printf("%d %d\\n", f(0, 0), g(0, 0)); }

int main() {
  init();
  while (true) {
    scanf("%d", &N);
    if (!N) {
      break;
    }
    solve();
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define INF 100000000
using namespace std;

const int M = 1000000;
int N, dp1[M + 1], dp2[M + 1];

int main(void) {
  REP(i, 1, M) dp1[i] = dp2[i] = i;

  for (int i = 1, n; n = i * (i + 1) * (i + 2) / 6, n <= M; i++) {
    dp1[n] = 1;
    if (n % 2 == 1)
      dp2[n] = 1;
    for (int j = 1; j + n <= M; j++) {
      dp1[j + n] = min(dp1[j + n], dp1[j] + 1);
      if (n % 2 == 1) {
        dp2[j + n] = min(dp2[j + n], dp2[j] + 1);
      }
    }
  }

  while (cin >> N, N) {
    cout << dp1[N] << " " << dp2[N] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define INF 100000000
using namespace std;

const int M = 1000000;
int N, base1[M + 1], base2[M + 2], dp1[M + 1], dp2[M + 1];
vector<int> b1, b2;

int dfs1(int n) {
  if (dp1[n] >= 0)
    return dp1[n];
  if (base1[n])
    return dp1[n] = 1;

  int ret = INF;
  for (int i : b1) {
    if (i < n)
      ret = min(ret, 1 + dfs1(n - i));
    else
      break;
  }
  return dp1[n] = ret;
}

int dfs2(int n) {
  if (dp2[n] >= 0)
    return dp2[n];
  if (base2[n])
    return dp2[n] = 1;

  int ret = INF;
  for (int i : b2) {
    if (i < n)
      ret = min(ret, 1 + dfs2(n - i));
    else
      break;
  }
  return dp2[n] = ret;
}

int main(void) {
  REP(i, 1, M) dp1[i] = dp2[i] = -1, base1[i] = base2[i] = 0;
  for (int i = 1, n; n = i * (i + 1) * (i + 2) / 6, n <= M; i++) {
    base1[n] = 1, b1.push_back(n);
    if (n % 2 == 1)
      base2[n] = 1, b2.push_back(n);
  }

  while (cin >> N, N) {
    cout << dfs1(N) << " " << dfs2(N) << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  int N, S[1000], SS[1000], SSS[1000], P[1000001], OP[1000001], a = 0;
  S[0] = 0;
  P[0] = 0;
  OP[0] = 0;
  for (int i = 1; i < 1000001; i++) {
    OP[i] = P[i] = 10000001;
  }
  for (int i = 1; i < 300; i++) {
    S[i] = S[i - 1] + i;
  }
  SS[0] = 0;
  for (int i = 1; i < 300; i++) {
    SS[i] = SS[i - 1] + S[i];
    if (SS[i] % 2 == 1)
      SSS[a++] = SS[i];
  }
  for (int i = 0; i < a; i++) {
    for (int j = SSS[i]; j < 1000001; j++) {
      OP[j] = min(OP[j], OP[j - SSS[i]] + 1);
    }
  }
  for (int i = 1; i < 300; i++) {
    for (int j = SS[i]; j < 1000001; j++) {
      P[j] = min(P[j], P[j - SS[i]] + 1);
    }
  }
  while (1) {
    cin >> N;
    if (N == 0)
      break;
    cout << P[N] << " " << OP[N] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int N, S[1000], SS[1000], SSS[1000], P[100001], OP[100001], a = 0;
  S[0] = 0;
  P[0] = 0;
  OP[0] = 0;
  for (int i = 1; i < 100001; i++) {
    OP[i] = P[i] = 10000001;
  }
  for (int i = 1; i < 190; i++) {
    S[i] = S[i - 1] + i;
  }
  SS[0] = 0;
  for (int i = 1; i < 190; i++) {
    SS[i] = SS[i - 1] + S[i];
    if (SS[i] % 2 == 1)
      SSS[a++] = SS[i];
  }
  for (int i = 0; i < a; i++) {
    for (int j = SSS[i]; j < 100001; j++) {
      OP[j] = min(OP[j], OP[j - SSS[i]] + 1);
    }
  }
  for (int i = 1; i < 190; i++) {
    for (int j = SS[i]; j < 100001; j++) {
      P[j] = min(P[j], P[j - SS[i]] + 1);
    }
  }
  while (1) {
    cin >> N;
    if (N == 0)
      break;
    cout << P[N] << " " << OP[N] << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Memory Limit Exceeded

//
//  main.cpp
//  AOJ1167
//
//  Created by aki33524 on 2014/07/09.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

const int MAX_N = 1000000;
const int MAX_T = 200;

vector<int> tetras;
vector<int> oddtetras;
int dp1[2][MAX_N];
int dp2[2][MAX_N];

void init() {
  memset(dp1, 0x3f, sizeof(dp1));
  memset(dp2, 0x3f, sizeof(dp2));

  for (int i = 0; i < MAX_T; i++) {
    int t = i * (i + 1) * (i + 2) / 6;
    tetras.push_back(t);
    if (t % 2)
      oddtetras.push_back(t);
  }

  for (int i = 0; i < tetras.size(); i++)
    dp1[0][tetras[i]] = 1;
  for (int i = 0; i < tetras.size(); i++) {
    int t = tetras[i];
    for (int j = 0; j < MAX_N; j++) {
      if (j < t) {
        dp1[(i + 1) & 1][j] = dp1[i & 1][j];
      } else {
        dp1[(i + 1) & 1][j] = min(dp1[i & 1][j], dp1[(i + 1) & 1][j - t] + 1);
      }
    }
  }

  for (int i = 0; i < oddtetras.size(); i++)
    dp2[0][oddtetras[i]] = 1;
  for (int i = 0; i < oddtetras.size(); i++) {
    int t = oddtetras[i];
    for (int j = 0; j < MAX_N; j++) {
      if (j < t) {
        dp2[(i + 1) & 1][j] = dp2[i & 1][j];
      } else {
        dp2[(i + 1) & 1][j] = min(dp2[i & 1][j], dp2[(i + 1) & 1][j - t] + 1);
      }
    }
  }
}

int main(int argc, const char *argv[]) {
  init();

  int N;
  while (cin >> N, N) {
    cout << dp1[tetras.size() & 1][N] << " " << dp2[oddtetras.size() & 1][N]
         << endl;
    ;
  }

  return 0;
}

Error: MLE

Fixed submission:

//
//  main.cpp
//  AOJ1167
//
//  Created by aki33524 on 2014/07/09.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

const int MAX_N = 1000000;
const int MAX_T = 200;

vector<int> tetras;
vector<int> oddtetras;
int dp1[MAX_T + 1][MAX_N];
int dp2[MAX_T + 1][MAX_N];

void init() {
  memset(dp1, 0x3f, sizeof(dp1));
  memset(dp2, 0x3f, sizeof(dp2));

  for (int i = 0; i < MAX_T; i++) {
    int t = i * (i + 1) * (i + 2) / 6;
    tetras.push_back(t);
    if (t % 2)
      oddtetras.push_back(t);
  }

  for (int i = 0; i < tetras.size(); i++)
    dp1[0][tetras[i]] = 1;
  for (int i = 0; i < tetras.size(); i++) {
    int t = tetras[i];
    for (int j = 0; j < MAX_N; j++) {
      if (j < t) {
        dp1[i + 1][j] = dp1[i][j];
      } else {
        dp1[i + 1][j] = min(dp1[i][j], dp1[i + 1][j - t] + 1);
      }
    }
  }

  for (int i = 0; i < oddtetras.size(); i++)
    dp2[0][oddtetras[i]] = 1;
  for (int i = 0; i < oddtetras.size(); i++) {
    int t = oddtetras[i];
    for (int j = 0; j < MAX_N; j++) {
      if (j < t) {
        dp2[i + 1][j] = dp2[i][j];
      } else {
        dp2[i + 1][j] = min(dp2[i][j], dp2[i + 1][j - t] + 1);
      }
    }
  }
}

int main(int argc, const char *argv[]) {
  init();

  int N;
  while (cin >> N, N) {
    cout << dp1[tetras.size()][N] << " " << dp2[oddtetras.size()][N] << endl;
    ;
  }

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a) for (i = 0; i < (a); i++)
#define FORM(i, a) for (i = (a)i >= 0; i--)
#define INF 100000
using namespace std;
int c[1000], odd[1000];
int mini[1000001];
int miniodd[1000001];
int main() {
  int i, j, W, minimumc, minimumodd, l;

  for (i = 1; i <= 200; i++) {
    c[i] = (i * (i + 1) * (i + 2)) / 6;
  }
  j = 1;
  for (i = 1; i <= 200; i++) {
    if (c[i] % 2 == 1) {
      odd[j] = c[i];
      j += 1;
    }
  }

  FOR(i, 1000000) {
    mini[i] = 10000000;
    miniodd[i] = 10000000;
  }
  mini[0] = 0;
  miniodd[0] = 0;
  for (j = 1; j <= 180; j++) {
    for (i = c[j]; i <= 1000000; i++) {
      mini[i] = min(mini[i], mini[i - c[j]] + 1);
    }
  }
  for (j = 1; j <= 50; j++) {
    for (i = odd[j]; i <= 1000000; i++) {
      miniodd[i] = min(miniodd[i], miniodd[i - odd[j]] + 1);
    }
  }

  cin >> W;

  while (W != 0) {
    cout << mini[W] << " " << miniodd[W] << endl;

    cin >> W;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a) for (i = 0; i < (a); i++)
#define FORM(i, a) for (i = (a)i >= 0; i--)
#define INF 100000
using namespace std;
int c[1000], odd[1000];
int mini[180];

int main() {
  int i, j, W, minimum, l;

  for (i = 1; i <= 180; i++) {
    c[i] = (i * (i + 1) * (i + 2)) / 6;
  }
  j = 1;
  for (i = 1; i <= 180; i++) {
    if (c[i] % 2 == 1) {
      odd[j] = c[i];
      j += 1;
    }
  }

  cin >> W;

  while (W != 0) {
    minimum = 10000000;
    for (i = 1; i <= 180; i++) {
      l = W;
      if (c[i] > W) {
        break;
      }
      for (j = i; j > 0; j--) {
        mini[i] += l / c[j];
        l %= c[j];
      }

      minimum = min(minimum, mini[i]);
    }

    cout << minimum << " ";
    minimum = 1000000;
    FOR(i, 181) { mini[i] = 0; }
    for (i = 1; i <= 180; i++) {
      l = W;
      if (odd[i] > W) {
        break;
      }
      for (j = i; j > 0; j--) {
        mini[i] += l / odd[j];
        l %= odd[j];
      }

      minimum = min(minimum, mini[i]);
    }

    cout << minimum << endl;
    FOR(i, 181) { mini[i] = 0; }

    cin >> W;
  }

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

#include <iostream>
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++)
#define MAX 1004732

int calc(int n) { return n * (n + 1) * (n + 2) / 6; }
int p[200];
int p1[200];
// int dp[MAX] = { 0 };
// int dp1[MAX] = { 0 };

int func(int n, int P[], int DP[]) {
  if (n <= 0)
    return MAX;
  if (DP[n] != 0)
    return DP[n];
  else {
    int min_t = MAX;
    int i = 0;
    while (1) {
      if (P[i] <= n && n <= P[i + 1])
        break;
      if (P[i] == 1004731) {
        i--;
        break;
      }
      i++;
    }
    for (int t = i; t > 0; t--) {
      int temp = func(n - P[t], P, DP);
      if (min_t > temp + 1) {
        min_t = temp + 1;
      }
    }
    DP[n] = min_t;
    return DP[n];
  }
}

int main() {
  int *dp, *dp1;
  dp = new int[MAX];
  dp1 = new int[MAX];
  REP(i, MAX) {
    dp[i] = 0;
    dp1[i] = 0;
  }
  int index = 1;
  FOR(i, 1, 200) {
    int temp = calc(i);
    if (temp > 1004731)
      break;
    p[i] = temp;
    dp[p[i]] = 1;
    if (temp % 2 == 1) {
      p1[index] = temp;
      dp1[p1[index]] = 1;
      index++;
    }
  }
  while (1) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    cout << func(N, p, dp) << " " << func(N, p1, dp1) << endl;
  }
  delete[] dp;
  delete[] dp1;
}

Error: -11

Fixed submission:

#include <iostream>
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++)
#define MAX 1000000

int calc(int n) { return n * (n + 1) * (n + 2) / 6; }
int p[200];
int p1[200];
int dp[MAX] = {0};
int dp1[MAX] = {0};

int func(int n, int P[], int DP[]) {
  if (n <= 0)
    return MAX;
  if (DP[n] != 0)
    return DP[n];
  else {
    int min_t = MAX;
    int i = 0;
    while (1) {
      if (P[i] <= n && n <= P[i + 1])
        break;
      if (P[i] == 1004731) {
        i--;
        break;
      }
      i++;
    }
    for (int t = i; t > 0; t--) {
      int temp = func(n - P[t], P, DP);
      if (min_t > temp + 1) {
        min_t = temp + 1;
      }
    }
    DP[n] = min_t;
    return DP[n];
  }
}

int main() {
  int index = 1;
  FOR(i, 1, 200) {
    int temp = calc(i);
    if (temp > 1004731)
      break;
    p[i] = temp;
    dp[p[i]] = 1;
    if (temp % 2 == 1) {
      p1[index] = temp;
      dp1[p1[index]] = 1;
      index++;
    }
  }
  while (1) {
    int N;
    cin >> N;
    if (N == 0)
      return 0;
    cout << func(N, p, dp) << " " << func(N, p1, dp1) << endl;
  }
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define INF 1 << 25

int dp[1500000];
int dp2[1500000];

int main() {
  int n;
  int tetra[200];
  for (int i = 0; i < 200; i++)
    tetra[i] = (i + 1) * (i + 2) * (i + 3) / 6;
  for (int i = 0; i < 1500000; i++)
    dp[i] = dp2[i] = INF;
  dp[0] = dp2[0] = 0;
  for (int i = 0; i < 200; i++) {
    dp[tetra[i]] = 1;
    if (tetra[i] % 2 == 1)
      dp2[tetra[i]] = 1;
  }
  for (int i = 0; i < 200; i++) {
    for (int j = 0; j + tetra[i] <= 1000000; j++) {
      dp[j + tetra[i]] = min(dp[j + tetra[i]], dp[j] + dp[tetra[i]]);
      if (tetra[i] % 2)
        dp2[j + tetra[i]] = min(dp2[j + tetra[i]], dp2[j] + dp2[tetra[i]]);
    }
  }
  while (cin >> n, n) {
    cout << dp[n] << " " << dp2[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define INF 1 << 25

int dp[1500000];
int dp2[1500000];

int main() {
  int n;
  int tetra[200];
  for (int i = 0; i < 200; i++)
    tetra[i] = (i + 1) * (i + 2) * (i + 3) / 6;
  while (cin >> n, n) {
    for (int i = 0; i < 1500000; i++)
      dp[i] = dp2[i] = INF;
    dp[0] = dp2[0] = 0;
    for (int i = 0; i < 200; i++) {
      dp[tetra[i]] = 1;
      if (tetra[i] % 2 == 1)
        dp2[tetra[i]] = 1;
    }
    for (int i = 2; i <= n; i++) {
      for (int j = 1; j < i; j++) {
        dp[i] = min(dp[i], dp[i - j] + dp[j]);
        dp2[i] = min(dp2[i], dp2[i - j] + dp2[j]);
      }
    }
    cout << dp[n] << " " << dp2[n] << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int dp[1000001], dp2[1000001];

vector<int> item;

int main() {
  int n;
  for (int i = 1; i * (i + 1) * (i + 2) / 6 <= 1000000; i++)
    item.push_back(i * (i + 1) * (i + 2) / 6);
  rep(i, 1000001) dp[i] = 9999;
  rep(i, 1000001) dp2[i] = 9999;
  dp[0] = dp2[0] = 0;

  for (int i = 0; i <= 1000000; i++) {
    for (int j = 0; j < item.size() && item[j] + i <= 1000000; j++) {
      dp[i + item[j]] = min(dp[i + item[j]], dp[i] + 1);
    }
  }
  for (int i = 0; i <= 1000000; i++) {
    for (int j = 0; j < item.size() && item[j] + i <= 1000000; j++) {
      if (item[j] % 2)
        dp2[i + item[j]] = min(dp2[i + item[j]], dp2[i] + 1);
    }
  }

  while (cin >> n && n) {
    cout << dp[n] << " " << dp2[n] << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int dp[100001], dp2[100001];

vector<int> item;

int main() {
  int n;
  for (int i = 1; i * (i + 1) * (i + 2) / 6 <= 100000; i++)
    item.push_back(i * (i + 1) * (i + 2) / 6);
  rep(i, 100001) dp[i] = 9999;
  rep(i, 100001) dp2[i] = 9999;
  dp[0] = dp2[0] = 0;

  for (int i = 0; i <= 100000; i++) {
    for (int j = 0; j < item.size() && item[j] + i <= 100000; j++) {
      dp[i + item[j]] = min(dp[i + item[j]], dp[i] + 1);
    }
  }
  for (int i = 0; i <= 100000; i++) {
    for (int j = 0; j < item.size() && item[j] + i <= 100000; j++) {
      if (item[j] % 2)
        dp2[i + item[j]] = min(dp2[i + item[j]], dp2[i] + 1);
    }
  }

  while (cin >> n && n) {
    cout << dp[n] << " " << dp2[n] << endl;
  }
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
#define N 1000000
#define INFINITY 2000000000
using namespace std;
int DP(int);
int DP2(int);
int m = 1, m2 = 1;
int dp[N], dp2[N], data[N];
vector<int> data2;
int main() {
  int i, out, out2, n, c;
  data2.push_back(0);
  for (i = 1; i < N; i++) {
    data[i] = i * (i + 1) * (i + 2) / 6;
    if (data[i] > N) {
      c = i;
    }
    if (data[i] % 2 == 1) {
      data2.push_back(data[i]);
    }
  }
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    out = DP(n);
    out2 = DP2(n);
    cout << out << ' ' << out2 << endl;
  }
  return 0;
}
int DP(int n) {
  int i, j, s;
  for (i = 1; i < N; i++) {
    if (data[i] > n) {
      s = i - 1;
      break;
    }
  }
  if (s >= m) {
    m = s;
    for (i = 0; i <= n; i++)
      dp[i] = INFINITY;
    dp[0] = 0;
    for (i = 1; i <= s; i++) {
      for (j = data[i]; j <= n; j++) {
        dp[j] = min(dp[j], dp[j - data[i]] + 1);
      }
    }
  }
  return dp[n];
}
int DP2(int n) {
  int i, j, s, len;
  len = data2.size();
  for (i = 1; i < len; i++) {
    if (data2[i] > n) {
      s = i - 1;
      break;
    }
  }
  if (s >= m2) {
    m2 = s;
    for (i = 0; i <= n; i++)
      dp2[i] = INFINITY;
    dp2[0] = 0;
    for (i = 1; i <= s; i++) {
      for (j = data2[i]; j <= n; j++) {
        dp2[j] = min(dp2[j], dp2[j - data2[i]] + 1);
      }
    }
  }
  return dp2[n];
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define N 1000000
#define INFINITY 2000000000
using namespace std;
int dp[N], data[N];
vector<int> data2;
int DP(int);
int DP2(int);
int main() {
  int i, out, out2, n, c;
  data2.push_back(0);
  for (i = 1; i < N; i++) {
    data[i] = i * (i + 1) * (i + 2) / 6;
    if (data[i] > N) {
      c = i;
    }
    if (data[i] % 2 == 1) {
      data2.push_back(data[i]);
    }
  }
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    out = DP(n);
    out2 = DP2(n);
    cout << out << ' ' << out2 << endl;
  }
  return 0;
}
int DP(int n) {
  int i, j, minret, s;
  for (i = 1; i < N; i++) {
    if (data[i] > n) {
      s = i - 1;
      break;
    }
  }
  for (i = 0; i <= n; i++)
    dp[i] = INFINITY;
  dp[0] = 0;
  for (i = 1; i <= s; i++) {
    for (j = data[i]; j <= n; j++) {
      dp[j] = min(dp[j], dp[j - data[i]] + 1);
    }
  }
  return dp[n];
}
int DP2(int n) {
  int i, j, minret, s, len;
  len = data2.size();
  for (i = 1; i < len; i++) {
    if (data2[i] > n) {
      s = i - 1;
      break;
    }
  }
  for (i = 0; i <= n; i++)
    dp[i] = INFINITY;
  dp[0] = 0;
  for (i = 1; i <= s; i++) {
    for (j = data2[i]; j <= n; j++) {
      dp[j] = min(dp[j], dp[j - data2[i]] + 1);
    }
  }
  return dp[n];
}