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

#include <algorithm>
#include <iostream>
using namespace std;
int dp[2][1000001];
int odd[2][1000001];
int Odd(int n, int w) {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j <= n; j++) {
      odd[i][j] = 99999999;
      if (i == 0)
        odd[i][j] = j;
      if (j == 0)
        odd[i][j] = 0;
    }

  for (int i = 1; i <= w; i++) {
    for (int j = 1; j <= n; j++) {
      if ((i * (i + 1) * (i + 2) / 6) % 2 == 0) {
        odd[i & 1][j] = odd[i & 1 ^ 1][j];
      } else if (j < i * (i + 1) * (i + 2) / 6) {
        odd[i & 1][j] = odd[i & 1 ^ 1][j];
      } else {
        odd[i & 1][j] = min(odd[i & 1 ^ 1][j],
                            odd[i & 1][j - i * (i + 1) * (i + 2) / 6] + 1);
      }
    }
  }
  return 1;
}

int main() {
  int n = 1000000;
  int w = 300;
  for (int i = 0; i < 2; i++)
    for (int j = 0; j <= n; j++) {
      dp[i][j] = 99999999;
      if (i == 0)
        dp[i][j] = j;
      if (j == 0)
        dp[i][j] = 0;
    }
  for (int i = 1; i <= w; i++) {
    for (int j = 1; j <= n; j++) {
      if (j < i * (i + 1) * (i + 2) / 6) {
        dp[i & 1][j] = dp[i & 1 ^ 1][j];
      } else {
        dp[i & 1][j] =
            min(dp[i & 1 ^ 1][j], dp[i & 1][j - i * (i + 1) * (i + 2) / 6] + 1);
      }
      // cout << "dp[" << i << "][" << j <<"]:"<< dp[i][j] << endl;
    }
  }
  int a;
  Odd(n, w);
  while (cin >> a, a) {
    int b = 0;
    while (b * (b + 1) * (b + 2) / 6 < a)
      b++;
    cout << dp[b % 2][a] << " " << odd[b % 2][a] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int dp[2][1000001];

int odd(int n, int w) {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j <= n; j++) {
      dp[i][j] = 99999999;
      if (i == 0)
        dp[i][j] = j;
      if (j == 0)
        dp[i][j] = 0;
    }

  for (int i = 1; i <= w; i++) {
    for (int j = 1; j <= n; j++) {
      if ((i * (i + 1) * (i + 2) / 6) % 2 == 0) {
        dp[i & 1][j] = dp[i & 1 ^ 1][j];
      } else if (j < i * (i + 1) * (i + 2) / 6) {
        dp[i & 1][j] = dp[i & 1 ^ 1][j];
      } else {
        dp[i & 1][j] =
            min(dp[i & 1 ^ 1][j], dp[i & 1][j - i * (i + 1) * (i + 2) / 6] + 1);
      }
      // cout << "dp[" << i << "][" << j <<"]:"<< dp[i][j] << endl;
    }
  }
  return dp[w % 2][n];
}

int main() {
  int n;
  while (cin >> n, n) {
    int w = 0;
    while (w * (w + 1) * (w + 2) / 6 < n) {
      w++;
    }
    for (int i = 0; i < 2; i++)
      for (int j = 0; j <= n; j++) {
        dp[i][j] = 99999999;
        if (i == 0)
          dp[i][j] = j;
        if (j == 0)
          dp[i][j] = 0;
      }
    for (int i = 1; i <= w; i++) {
      for (int j = 1; j <= n; j++) {
        if (j < i * (i + 1) * (i + 2) / 6) {
          dp[i & 1][j] = dp[i & 1 ^ 1][j];
        } else {
          dp[i & 1][j] = min(dp[i & 1 ^ 1][j],
                             dp[i & 1][j - i * (i + 1) * (i + 2) / 6] + 1);
        }
        // cout << "dp[" << i << "][" << j <<"]:"<< dp[i][j] << endl;
      }
    }
    cout << dp[w % 2][n] << " " << odd(n, w) << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int dp1[1000001], dp2[1000001];
int main() {
  int c1[100000], c2[100000], i, m, p = 0, k;
  for (i = 0; i * (i + 1) * (i + 2) / 6 <= 1000000; i++) {
    c1[i] = i * (i + 1) * (i + 2) / 6;
    if (c1[i] % 2 == 1) {
      c2[p] = c1[i];
      p++;
    }
  }
  for (int j = 0; j <= 1000000; j++) {
    dp1[j] = j;
    dp2[j] = j;
    for (int k = 0; k < i; k++) {
      if (j - c1[k] >= 0)
        dp1[j] = min(dp1[j], dp1[j - c1[k]] + 1);
      if (k < p) {
        if (j - c2[k] >= 0) {
          dp2[j] = min(dp2[j], dp2[j - c2[k]] + 1);
        }
      }
    }
  }

  while (1) {
    cin >> m;
    if (m == 0)
      break;

    cout << dp1[m] << " " << dp2[m] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int c1[100000], c2[100000], i, m, p = 0, dp1[100001], dp2[100001], k;
  for (i = 0; i * (i + 1) * (i + 2) / 6 <= 100000; i++) {
    c1[i] = i * (i + 1) * (i + 2) / 6;
    if (c1[i] % 2 == 1) {
      c2[p] = c1[i];
      p++;
    }
  }
  while (1) {
    cin >> m;
    if (m == 0)
      break;
    for (int j = 0; j <= m; j++) {
      dp1[j] = j;
      dp2[j] = j;
      for (int k = 0; k < i; k++) {
        if (j - c1[k] >= 0)
          dp1[j] = min(dp1[j], dp1[j - c1[k]] + 1);
        if (k < p)
          if (j - c2[k] >= 0) {
            dp2[j] = min(dp2[j], dp2[j - c2[k]] + 1);
          }
      }
    }
    cout << dp1[m] << " " << dp2[m] << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int MAX;
vector<int> V;
vector<int> D;
int N;
int M;
bool dp[10][1000100] = {0};

void solve(int n) {
  memset(dp, 0, sizeof(dp));

  int ans = 1;

  for (int i = 0; i < N && V[i] <= n; i++)
    dp[0][V[i]] = 1;

  for (int i = 1; i < 6 && !dp[i - 1][n]; i++) {
    ans++;
    for (int j = 0; j <= n; j++) {
      if (!dp[i - 1][j])
        continue;
      for (int k = 0; k < N && j + V[k] <= n; k++)
        dp[i][j + V[k]] = 1;
    }
  }

  cout << ans << " ";

  memset(dp, 0, sizeof(dp));

  ans = 1;

  for (int i = 0; i < M && D[i] <= n; i++)
    dp[0][D[i]] = 1;

  for (int i = 1; i <= MAX && !dp[1 - i % 2][n]; i++) {
    ans++;
    for (int j = 0; j <= n; j++)
      dp[i % 2][j] = 0;
    for (int j = 0; j <= n; j++) {
      if (!dp[1 - i % 2][j])
        continue;
      for (int k = 0; k < M && j + D[k] <= n; k++)
        dp[i % 2][j + D[k]] = 1;
    }
  }

  cout << ans << endl;
}

int main() {
  MAX = (int)pow(10.0, 6);
  for (int i = 1; i * (i + 1) * (i + 2) / 6 <= MAX; i++) {
    V.push_back(i * (i + 1) * (i + 2) / 6);
    if (V[i - 1] % 2 == 1)
      D.push_back(i * (i + 1) * (i + 2) / 6);
  }
  N = (int)V.size();
  M = (int)D.size();

  int n;
  cin >> n;
  while (n != 0) {
    solve(n);
    cin >> n;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int MAX;
vector<int> V;
vector<int> D;
int N;
int M;
bool dp[10][1000100] = {0};

void solve(int n) {
  memset(dp, 0, sizeof(dp));

  int ans = 1;

  for (int i = 0; V[i] <= n; i++)
    dp[0][V[i]] = 1;

  for (int i = 1; i < 5 && !dp[i - 1][n]; i++) {
    ans++;
    for (int j = 0; j <= n; j++) {
      if (!dp[i - 1][j])
        continue;
      for (int k = 0; j + V[k] <= n; k++)
        dp[i][j + V[k]] = 1;
    }
  }

  cout << ans << " ";

  memset(dp, 0, sizeof(dp));

  ans = 1;

  for (int i = 0; D[i] <= n; i++)
    dp[0][D[i]] = 1;

  for (int i = 1; i <= 1000000 && !dp[1 - i % 2][n]; i++) {
    ans++;
    for (int j = 0; j <= n; j++)
      dp[i][j] = 0;
    for (int j = 0; j <= n; j++) {
      if (!dp[1 - i % 2][j])
        continue;
      for (int k = 0; j + D[k] <= n; k++)
        dp[i % 2][j + D[k]] = 1;
    }
  }

  cout << ans << endl;
}

int main() {
  MAX = (int)pow(10.0, 6);
  for (int i = 1; i * (i + 1) * (i + 2) / 6 <= MAX; i++) {
    V.push_back(i * (i + 1) * (i + 2) / 6);
    if (V[i - 1] % 2 == 1)
      D.push_back(i * (i + 1) * (i + 2) / 6);
  }
  N = (int)V.size();
  M = (int)D.size();

  int n;
  cin >> n;
  while (n != 0) {
    solve(n);
    cin >> n;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 100000000;

const int tetra_size = 185;
int tetra[tetra_size];
int tri[tetra_size];
void settetra() {
  tetra[0] = 0;
  tri[0] = 0;
  for (int i = 1; i < tetra_size; i++) {
    tri[i] = tri[i - 1] + i;
    tetra[i] = tetra[i - 1] + tri[i];
  }
}

int dp[1000001];
int dpodd[1000001];
void setdp() {
  fill(dp, dp + 1000001, INF);
  dp[0] = 0;
  fill(dpodd, dpodd + 1000001, INF);
  dpodd[0] = 0;
  for (int i = tetra_size; i >= 1; i--) {
    for (int j = 0; j + tetra[i] < 1000001; j++) {
      if (dp[j] == INF)
        continue;
      dp[j + tetra[i]] = min(dp[j] + 1, dp[j + tetra[i]]);
      if (tetra[i] % 2 == 1)
        dpodd[j + tetra[i]] = min(dpodd[j] + 1, dpodd[j + tetra[i]]);
    }
  }
}

int main() {
  settetra();
  setdp();
  int n;
  while (cin >> n, n) {
    // cout << tetra[n]  << endl;
    cout << dp[n] << ' ' << dpodd[n] << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 100000000;

const int tetra_size = 200;
int tetra[tetra_size];
int tri[tetra_size];
void settetra() {
  tetra[0] = 0;
  tri[0] = 0;
  for (int i = 1; i < tetra_size; i++) {
    tri[i] = tri[i - 1] + i;
    tetra[i] = tetra[i - 1] + tri[i];
  }
}

int dp[100001];
int dpodd[100001];
void setdp() {
  fill(dp, dp + 100001, INF);
  dp[0] = 0;
  fill(dpodd, dpodd + 100001, INF);
  dpodd[0] = 0;
  for (int i = 1; i < tetra_size; i++) {
    for (int j = 0; j + tetra[i] < 100001; j++) {
      if (dp[j] == INF)
        continue;
      dp[j + tetra[i]] = min(dp[j] + 1, dp[j + tetra[i]]);
      if (tetra[i] % 2 == 1)
        dpodd[j + tetra[i]] = min(dpodd[j] + 1, dpodd[j + tetra[i]]);
    }
  }
}

int main() {
  settetra();
  setdp();
  int n;
  while (cin >> n) {
    cout << dp[n] << ' ' << dpodd[n] << endl;
  }

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

#include "bits/stdc++.h"
using namespace std;
#define MAXN 1000000
#define ll long long

ll dp[MAXN + 1];
ll Odp[MAXN + 1];

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

  for (int i = 0; i < MAXN + 1; i++) {
    dp[i] = i;
    Odp[i] = i;
  }
  // n := n???????????£?????¢???
  // p := ??£?????¢?????°
  // n = 1 p = 1 ?????´???????????????
  // n = 2, p = 2*3*4/6 = 4??????
  ll p = 4;
  for (int n = 2; p <= MAXN; n++) {
    p = n * (n + 1) * (n + 2) / 6;
    // cout << n << " " << p << endl;
    for (int i = 0; i + p <= MAXN; i++) {
      dp[i + p] = min(dp[i + p], dp[i] + 1);
      if (p % 2 == 1) {
        Odp[i + p] = min(Odp[i + p], Odp[i] + 1);
      }
    }
  }
  int N;
  while (cin >> N, N) {
    cout << dp[N] << " " << Odp[N] << endl;
  }
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
#define MAXN 1000000
#define ll long long

ll dp[MAXN + 10];
ll Odp[MAXN + 10];

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

  for (int i = 0; i < MAXN + 10; i++) {
    dp[i] = i;
    Odp[i] = i;
  }
  // n := n???????????£?????¢???
  // p := ??£?????¢?????°
  // n = 1 p = 1 ?????´???????????????
  // n = 2, p = 2*3*4/6 = 4??????
  ll p;
  for (int n = 2; n <= MAXN; n++) {
    p = n * (n + 1) * (n + 2) / 6;
    for (int i = 0; i + p <= MAXN; i++) {
      dp[i + p] = min(dp[i + p], dp[i] + 1);
      if (p % 2 == 1) {
        Odp[i + p] = min(Odp[i + p], Odp[i] + 1);
      }
    }
  }
  int N;
  while (cin >> N, N) {
    cout << dp[N] << " " << Odp[N] << endl;
  }
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define MAX 1000000
using namespace std;
int ans1[MAX + 10], ans2[MAX + 10], box[300];
void tab_make() {
  for (int i = 1;; i++) {
    box[i] = (i * (i + 1) * (i + 2) / 6);
    if (i * (i + 1) * (i + 2) / 6 > MAX)
      break;
  }
}
void ans_make() {
  ans1[0] = ans2[0] = 0;
  for (int i = 1; i <= MAX; i++) {
    ans1[i] = ans2[i] = i;
    for (int j = 1; i - box[j] >= 0; j++) {
      ans1[i] = min(ans1[i], ans1[i - box[j]] + 1);
      if (box[j] % 2 == 1)
        ans2[i] = min(ans2[i], ans2[i - box[j]] + 1);
    }
  }
}
int main() {
  int x;
  tab_make();
  ans_make();
  while (cin >> x, x) {
    cout << ans1[x] << ' ' << ans2[x] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define MAX 1000000
using namespace std;
int ans1[MAX + 10], ans2[MAX + 10], box[200];
void tab_make() {
  for (int i = 1; i * (i + 1) * (i + 2) / 6 <= MAX; i++)
    box[i] = (i * (i + 1) * (i + 2) / 6);
}
void ans_make() {
  ans1[0] = ans2[0] = 0;
  for (int i = 1; i <= MAX; i++) {
    ans1[i] = ans2[i] = i;
    for (int j = 1; i - box[j] >= 0; j++) {
      ans1[i] = min(ans1[i], ans1[i - box[j]] + 1);
      if (box[j] % 2 == 1)
        ans2[i] = min(ans2[i], ans2[i - box[j]] + 1);
    }
  }
}
int main() {
  int x;
  tab_make();
  ans_make();
  while (cin >> x, x) {
    cout << ans1[x] << ' ' << ans2[x] << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

#define N 1000000

using namespace std;

int min(int a, int b) {
  if (a >= b)
    return b;
  else
    return a;
}

int main() {

  int *data;
  int *data2;
  data = new int[N];
  data2 = new int[N];
  int *square;
  int squareLength = 0;

  int *square2;
  int square2Length = 0;

  square = new int[N];
  square2 = new int[N];

  for (int i = 0; i < N; i++) {
    data[i] = N;
    data2[i] = N;
  }

  for (int i = 1; i * (i + 1) * (i + 2) / 6 <= N; i++) {
    data[i * (i + 1) * (i + 2) / 6] = 1;
    square[squareLength] = i * (i + 1) * (i + 2) / 6;
    squareLength++;
    if ((i * (i + 1) * (i + 2) / 6 % 2) == 1) {
      data2[i * (i + 1) * (i + 2) / 6] = 1;
      square2[square2Length] = i * (i + 1) * (i + 2) / 6;
      square2Length++;
    }
  }

  /*
          for(int i=0;i<squareLength;i++){
                  cout<<square[i]<<endl;
          }
  */
  for (int i = 1; i < N; i++) {
    for (int j = 0; j < squareLength; j++) {
      if (i - square[j] < 0)
        continue;
      data[i] = min(data[i], data[i - square[j]] + 1);
    }
    for (int j = 0; j < square2Length; j++) {
      if (i - square2[j] < 0)
        continue;
      data2[i] = min(data2[i], data2[i - square2[j]] + 1);
    }
  }

  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    cout << data[n] << " " << data2[n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

#define INF 10000000

using namespace std;

long long int data[1000100];
long long int data2[1000100];

int min1, min2;

void solveMin1(int cnt, int sum, int objSum, int nowNum) {

  if ((cnt == min1 - 1 && sum != objSum) || cnt > 7)
    return;

  else if (sum == objSum) {
    if (min1 >= cnt) {
      min1 = cnt;
      return;
    }
  } else {
    for (int i = nowNum; sum + data[i] <= objSum; i++) {
      solveMin1(cnt + 1, sum + data[i], objSum, i);
    }
  }
}

void solveMin2(int cnt, int sum, int objSum, int nowNum) {

  if (cnt > min2 || sum > objSum)
    return;

  else if (sum == objSum) {
    if (min2 >= cnt) {
      min2 = cnt;
      return;
    }
  } else {
    for (int i = nowNum; i >= 0; i--) {
      solveMin2(cnt + 1, sum + data2[i], objSum, i);
    }
  }
}

int main() {
  int cnt = 0;

  for (long long int i = 0; i < 1000100; i++) {
    data[i] = i * (i + 1) * (i + 2) / 6;
    if (data[i] % 2 == 1) {
      data2[cnt] = data[i];
      cnt++;
      // cout<<data2[cnt-1]<<endl;
    }
  }

  int n;

  while (cin >> n) {
    if (n == 0)
      break;

    min1 = INF;
    min2 = INF;

    solveMin1(0, 0, n, 1);

    int nowNum = 0;
    for (nowNum = 0; data2[nowNum] <= n; nowNum++)
      ;

    // min2の予想をする。
    int objNum = n;
    min2 = 0;
    while (1) {
      while (data2[nowNum] > objNum) {
        nowNum--;
      }
      objNum -= data2[nowNum];
      min2++;
      if (objNum == 0)
        break;
    }

    // solveMin2(0,0,n,nowNum);

    cout << min1 << " " << min2 << endl;
  }

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

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

#define LIM 1000000
int all[LIM];
int odd[LIM];

int main() {
  for (int i = 0; i < LIM; i++) {
    all[i] = i;
    odd[i] = i;
  }
  for (int i = 0; i < LIM; i++) {
    int x = i * (i + 1) * (i + 2) / 6;
    if (x > LIM)
      break;
    for (int j = x; j <= LIM; ++j) {
      all[j] = min(all[j], all[j - x] + 1);
    }
    if (x % 2 == 1) {
      for (int j = x; j <= LIM; ++j) {
        odd[j] = min(odd[j], odd[j - x] + 1);
      }
    }
  }

  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    cout << all[n] << " " << odd[n] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int lim = 10000;
  int all[lim];
  int even[lim];
  for (int i = 0; i < lim; i++) {
    all[i] = i;
    even[i] = i;
  }
  for (int i = 0; i < 181; i++) {
    int tmp = i * (i + 1) * (i + 2) / 6;
    if (tmp > lim)
      break;
    all[tmp] = 1;
    if (tmp % 2 == 1)
      even[tmp] = 1;
  }
  for (int i = 2; i < lim; i++) {
    for (int j = 1; j <= i / 2; j++) {
      all[i] = min(all[i], all[j] + all[i - j]);
      even[i] = min(even[i], even[j] + even[i - j]);
    }
  }

  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    cout << all[n] << " " << even[n] << endl;
  }

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

#include <algorithm>
#include <assert.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int normal[1001000];
int odd[1001000];

int main() {
  MEMSET(normal, 0x0f);
  MEMSET(odd, 0x0f);
  normal[0] = odd[0] = 0;
  REP(i, 1000001) {
    REP(j, 10000) {
      int plus = j * (j + 1) * (j + 2) / 6;
      if (i + plus > 1000000) {
        break;
      }
      normal[i + plus] = min(normal[i + plus], normal[i] + 1);
      if (plus & 1) {
        odd[i + plus] = min(odd[i + plus], odd[i] + 1);
      }
    }
  }
  int n;
  while (scanf("%d", &n), n) {
    printf("%d %d\\n", normal[n], odd[n]);
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c)                                                           \\
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int normal[100100];
int odd[100100];

int main() {
  MEMSET(normal, 0x0f);
  MEMSET(odd, 0x0f);
  normal[0] = odd[0] = 0;
  REP(i, 100001) {
    REP(j, 1000) {
      int plus = j * (j + 1) * (j + 2) / 6;
      if (i + plus > 100000) {
        break;
      }
      normal[i + plus] = min(normal[i + plus], normal[i] + 1);
      if (plus & 1) {
        odd[i + plus] = min(odd[i + plus], odd[i] + 1);
      }
    }
  }
  int n;
  while (scanf("%d", &n), n) {
    printf("%d %d\\n", normal[n], odd[n]);
  }
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int MAX_N = 1000000;

vector<int> tetra;
vector<int> tetra_odd;

short dp[MAX_N + 1];
short dp_odd[MAX_N];

void init() {
  int n = 1;
  while (true) {
    int m = n * (n + 1) * (n + 2) / 6;
    if (m >= MAX_N * 10) {
      break;
    }
    tetra.push_back(m);
    if (m % 2 == 1) {
      tetra_odd.push_back(m);
    }
    n++;
  }
}

void solve() {
  dp[0] = dp_odd[0] = 0;
  for (int i = 1; i < MAX_N; i++) {
    short ans = 10;
    short ans_odd = 100;
    for (int j = 0; tetra[j] <= i; j++) {
      // cout << i << " " << tetra[j] << endl;
      ans = min(ans, dp[i - tetra[j]]);
    }

    for (int j = 0; tetra_odd[j] <= i; j++) {
      ans_odd = min(ans_odd, dp_odd[i - tetra_odd[j]]);
    }
    dp[i] = ans + 1;
    dp_odd[i] = ans_odd + 1;
    // cout << i << " " << dp[i] << " " << dp_odd[i] << endl;
  }
}

int main() {
  init();
  solve();
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }

    cout << dp[n] << " " << dp_odd[n] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int MAX_N = 1000000;

vector<int> tetra;
vector<int> tetra_odd;

int dp[MAX_N + 1];
int dp_odd[MAX_N + 1];

void init() {
  int n = 1;
  while (true) {
    int m = n * (n + 1) * (n + 2) / 6;
    if (m > MAX_N) {
      break;
    }
    tetra.push_back(m);
    if (m % 2 == 1) {
      tetra_odd.push_back(m);
    }
    n++;
  }
}

void solve() {
  dp[0] = dp_odd[0] = 0;
  for (int i = 1; i <= MAX_N; i++) {
    int ans = MAX_N;
    int ans_odd = MAX_N;
    for (int j = 0; tetra[j] <= i; j++) {
      // cout << i << " " << tetra[j] << endl;
      ans = min(ans, dp[i - tetra[j]]);
    }

    for (int j = 0; tetra_odd[j] <= i; j++) {
      ans_odd = min(ans_odd, dp_odd[i - tetra_odd[j]]);
    }
    dp[i] = ans + 1;
    dp_odd[i] = ans_odd + 1;
    // cout << i << " " << dp[i] << " " << dp_odd[i] << endl;
  }
}

int main() {
  init();
  solve();
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }

    cout << dp[n] << " " << dp_odd[n] << endl;
  }
}