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

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

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)

const int MAX = 1000000;

int dp[MAX + 1];
int dp2[MAX + 1];

void solve() {
  fill(dp, dp + MAX + 1, MAX);
  fill(dp2, dp2 + MAX + 1, MAX);
  dp[0] = dp2[0] = 0;
  vector<int> v;
  for (int i = 0;; i++) {
    int t = i * (i + 1) * (i + 2) / 6;
    if (t <= MAX)
      v.push_back(t);
    else
      break;
  }
  for (int i = 0; i <= MAX; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i + v[j] <= MAX) {
        if (v[j] & 1)
          dp2[i + v[j]] = min(dp2[i + v[j]], dp2[i] + 1);
        dp[i + v[j]] = min(dp[i + v[j]], dp[i] + 1);
      }
    }
  }
}

int main() {
  solve();
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    cout << dp[n] << " " << dp2[n] << endl;
  }
}

Error: TLE

Fixed submission:

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

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)

const int MAX = 1000000;

int dp[MAX + 1];
int dp2[MAX + 1];

void solve(int n) {
  vector<int> v;
  for (int i = 0;; i++) {
    int t = i * (i + 1) * (i + 2) / 6;
    if (t <= n)
      v.push_back(t);
    else
      break;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < v.size(); j++) {
      if (i + v[j] <= n) {
        if (v[j] & 1)
          dp2[i + v[j]] = min(dp2[i + v[j]], dp2[i] + 1);
        dp[i + v[j]] = min(dp[i + v[j]], dp[i] + 1);
      }
    }
  }
}

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    } else {
      fill(dp, dp + n + 1, MAX);
      fill(dp2, dp2 + n + 1, MAX);
      solve(n);
      cout << dp[n] << " " << dp2[n] << endl;
    }
  }
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <cassert>
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, l, n) for (int i = l; i < n; ++i)
int ans = 0;
int oddans = 0;
int pol[200];
int oddpol[100];
int oddpolcount = 0;
int memo[1000000];
int oddmemo[1000000];
int memorep(int n);
int oddmemorep(int n);
using namespace std;
int main() {
  pol[0] = 1;
  oddpol[oddpolcount++] = 1;
  int def = 3;
  int defdef = 3;
  REP(i, 1, 180) {
    pol[i] = pol[i - 1] + def;
    if (pol[i] % 2 == 1)
      oddpol[oddpolcount++] = pol[i];
    def += defdef++;
  }
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;
    ans = memorep(n);
    oddans = oddmemorep(n);
    int i = 0;
    cout << ans << " " << oddans << endl;
  }
  return 0;
}

int memorep(int n) {
  assert(n < 1000000);
  if (memo[n] != 0)
    return memo[n];
  int result;
  int min = 1000000;
  for (int i = 179; i >= 0; i--) {
    result = n - pol[i];
    if (result == 0) {
      return memo[n] = 1;
    }
    if (result > 0) {
      result = memorep(result) + 1;
      if (min > result)
        min = result;
    }
  }
  return memo[n] = min;
}

int oddmemorep(int n) {
  if (oddmemo[n] != 0)
    return oddmemo[n];
  int result;
  int min = 1000000;
  for (int i = oddpolcount - 1; i >= 0; i--) {
    result = n - oddpol[i];
    if (result == 0) {
      return oddmemo[n] = 1;
    }
    if (result > 0) {
      result = oddmemorep(result) + 1;
      if (min > result) {
        min = result;
      }
    }
  }
  return oddmemo[n] = min;
}

Error: 0

Fixed submission:

#include <iostream>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, l, n) for (int i = l; i < n; ++i)
int ans = 0;
int oddans = 0;
int pol[180];
int oddpol[50];
int oddpolcount = 0;
int memo[100000];
int oddmemo[1000000];
int memorep(int n);
int oddmemorep(int n);
using namespace std;
int main() {
  pol[0] = 1;
  oddpol[oddpolcount++] = 1;
  int def = 3;
  int defdef = 3;
  REP(i, 1, 180) {
    pol[i] = pol[i - 1] + def;
    if (pol[i] % 2 == 1)
      oddpol[oddpolcount++] = pol[i];
    def += defdef++;
  }
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;
    ans = memorep(n);
    oddans = oddmemorep(n);
    cout << ans << " " << oddans << endl;
  }
  return 0;
}

int memorep(int n) {
  if (memo[n] != 0)
    return memo[n];
  int result;
  int min = 100000;
  for (int i = 179; i >= 0; i--) {
    result = n - pol[i];
    if (result == 0) {
      return memo[n] = 1;
    }
    if (result > 0) {
      result = memorep(result) + 1;
      if (min > result)
        min = result;
    }
  }
  return memo[n] = min;
}

int oddmemorep(int n) {
  if (oddmemo[n] != 0)
    return oddmemo[n];
  int result;
  int min = 1000000;
  for (int i = oddpolcount - 1; i >= 0; i--) {
    result = n - oddpol[i];
    if (result == 0) {
      return oddmemo[n] = 1;
    }
    if (result > 0) {
      result = oddmemorep(result) + 1;
      if (min > result)
        min = result;
    }
  }
  return oddmemo[n] = min;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <fstream>
#include <iostream>

using namespace std;

#define MAX 1000000

int ans[MAX];
int ans_odd[MAX];

int square(int n) { return n * (n + 1) * (n + 2) / 6; }

int calc(int n) {

  if (ans[n] != MAX)
    return ans[n];

  int num = 0;
  while (square(num) <= n) {
    ans[square(num)] = 1;
    num++;
  }
  num--;

  for (int i = num; i > 0; i--) {
    int tmp = calc(n - square(i));
    if (ans[n] > tmp + 1)
      ans[n] = tmp + 1;
  }

  return ans[n];
}

int calcOdd(int n) {
  if (ans_odd[n] != MAX)
    return ans_odd[n];

  int num = 1;
  while (square(num) <= n) {
    ans_odd[square(num)] = 1;
    num += 4;
  }
  num -= 4;

  for (int i = num; i > 0; i -= 4) {
    int tmp = calcOdd(n - square(i));
    if (ans_odd[n] > tmp + 1)
      ans_odd[n] = tmp + 1;
  }

  return ans_odd[n];
}

int main() {
  //    ifstream fin("in.txt");
  int n = 0;

  for (int i = 0; i < MAX; i++) {
    ans[i] = ans_odd[i] = MAX;
  }

  while ((cin >> n), n) {

    cout << calc(n) << " " << calcOdd(n) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2510

#include <fstream>
#include <iostream>

#define N 1000 // データの最大個数
#define ami 0
#define mami 1

int n = 0;
int wTime[N] = {};

int sum(int a[]) {
  int ans = 0;
  for (int i = 0; a[i] != 0; i++)
    ans += a[i];
  return ans;
}

int timeCalc(int differ, int sum) {
  bool dp[10000] = {
      true,
  };

  // wTime[0 ? n-2]はsort済み
  int time = 0;
  int max = 0;

  for (int i = 0; i < n - 2; i++) {
    for (int j = differ; j >= wTime[i]; j--) {
      if (dp[j - wTime[i]])
        dp[j] = true;
      if (dp[j] && time < j)
        time = j;
    }
  }
  return time;
}

int main() {
  using namespace std;

  int rTime[N] = {};
  int allTime[2] = {0, 0};

  while (true) {
    cin >> n;
    if (n == 0)
      break; // 終了条件

    for (int i = 0; i < N; i++) { // 初期化
      rTime[i] = wTime[i] = 0;
    }

    for (int i = 0; i < n; i++) {
      cin >> rTime[i] >> wTime[i];
    }

    if (n == 1) {
      cout << 2 * rTime[0] + wTime[0] << endl;
      continue;
    }

    // 読書時間でbubble sort
    for (int i = n - 1; i >= 0; i--) {
      for (int j = 0; j < i; j++) {
        if (rTime[j] > rTime[j + 1]) {
          int tmp = rTime[j];
          rTime[j] = rTime[j + 1];
          rTime[j + 1] = tmp;
        }
      }
    }
    // 計算開始

    // read
    // 最も読む時間のかかる一つと、その他の全ての和を比較

    // max <= sum
    if (sum(rTime) >= 2 * rTime[n - 1]) {
      cout << sum(rTime) + sum(wTime) << endl;
    }

    // max > sum
    else if (sum(rTime) < 2 * rTime[n - 1]) {

      allTime[ami] = rTime[n - 1];
      allTime[mami] = sum(rTime) - rTime[n - 1];

      int differ = allTime[ami] - allTime[mami];

      for (int i = n - 2; i >= 0; i--) {
        for (int j = 0; j < i; j++) {
          if (wTime[j] > wTime[j + 1]) {
            int tmp = wTime[j];
            wTime[j] = wTime[j + 1];
            wTime[j + 1] = tmp;
          }
        }
      }

      int writingTime = timeCalc(differ, allTime[mami]);

      cout << sum(rTime) + sum(wTime) + differ - writingTime << endl;
    }
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

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

using P = pair<int, int>;

P solve(int n, vector<int> &v, vector<int> &w, vector<int> &ma,
        vector<int> &mb) {
  if (n == 0)
    return P(0, 0);
  if (ma[n] < 1e6)
    return P(ma[n], mb[n]);
  for (size_t i = 0; i < v.size(); ++i) {
    if (v[i] > n)
      break;
    if (v[i] == n) {
      ma[n] = 1;
      break;
    }
    ma[n] = min(ma[n], 1 + solve(n - v[i], v, w, ma, mb).first);
  }
  for (size_t i = 0; i < w.size(); ++i) {
    if (w[i] > n)
      break;
    if (w[i] == n) {
      mb[n] = 1;
      break;
    }
    mb[n] = min(mb[n], 1 + solve(n - w[i], v, w, ma, mb).second);
  }
  return P(ma[n], mb[n]);
}

int main() {
  //	cin.tie(0);
  //	ios::sync_with_stdio(false);
  const int N = 1'000'000;
  vector<int> v, w, ma(N, N), mb(N, N);
  for (int i = 1; i <= 1000; ++i) {
    int t = i * (i + 1) / 2 * (i + 2) / 3;
    v.push_back(t);
    if (t % 2 == 1)
      w.push_back(t);
  }
  for (int i = 1; i < N; ++i)
    solve(i, v, w, ma, mb);
  //	for(size_t i=0; i<v.size(); ++i) cout << i << " " << v[i] << "\\n";
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    cout << ma[n] << " " << mb[n] << "\\n";
  }
}


Error: 0

Fixed submission:

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

int func(int m, int p, vector<int> &q) {
  if (p == -1)
    return 0;
  int d = m / q[p];
  return d + func(m - d * q[p], p - 1, q);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> a, b;
  for (int i = 1; i * (i + 1) * (i + 2) / 6 < 1e6; ++i) {
    int t = i * (i + 1) * (i + 2) / 6;
    a.push_back(t);
    if (t % 2 == 1)
      b.push_back(t);
  }
  //	for(int i=0; i<a.size(); ++i)
  //		cout << a[i] << "\\n";
  //	cout << a.size() << "\\n";
  //	cout << b.size() << "\\n";
  //	for(int i=0; i<b.size(); ++i)
  //		cout << b[i] << "\\n";
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;
    int x = n, y = n;
    for (int i = 0; a[i] <= n; ++i)
      x = min(x, func(n, i, a));
    for (int i = 0; b[i] <= n; ++i)
      y = min(y, func(n, i, b));
    cout << x << " " << y << "\\n";
  }
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, b[1000001], c[1000001], a[200], n;
  for (i = 0; a[i - 1] < 1000000; i++)
    a[i] = i * (i + 1) * (i + 2) / 6;
  for (j = 0; j <= 1000000; j++)
    b[j] = c[j] = j;
  for (j = 2; j < i; j++) {
    for (k = a[j]; k <= 1000000; k++) {
      b[k] = min(b[k], b[k - a[j]] + 1);
      if (a[j] % 2) {
        c[k] = min(c[k], c[k - a[j]] + 1);
      }
    }
  }
  while (cin >> n, n) {
    cout << b[n] << ' ' << c[n] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[200], b[150], c[1000010], d[1000010], k = 0, i, j, n;

  for (i = 1; i < 200; i++)
    a[i - 1] = i * (i + 1) * (i + 2) / 6;

  for (j = 0; j < i; j++)
    if (a[j] % 2)
      b[k++] = a[j];

  for (i = 0; i < 1000010; i++)
    c[i] = d[i] = i;

  for (i = 1; i < 198; i++)
    for (j = a[i]; j < 1000010; j++) {
      c[j] = min(c[j], c[j - a[i]] + 1);
    }
  for (i = 1; i < k - 1; i++)
    for (j = b[i]; j < 10000010; j++) {
      d[j] = min(d[j], d[j - b[i]] + 1);
    }
  while (cin >> n, n)
    cout << c[n] << ' ' << d[n] << endl;
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int i, j, n, three[1000000], four[1000000], four_2[1000000], c[1000000],
    c_2[1000000];

int main() {

  three[0] = 1;
  four[0] = 1;
  for (i = 1; i < 1000000; i++)
    three[i] = i + 1 + three[i - 1];
  for (i = 1; i < 1000000; i++)
    four[i] = three[i] + four[i - 1];

  int k = 0;
  for (i = 0; i < 1000000; i++) {
    if (four[i] % 2 == 1) {
      four_2[k] = four[i];
      k++;
    }
  }

  for (i = 0; i < 1000000; i++) {
    c[i] = 2000000;
    c_2[i] = 2000000;
  }

  c[0] = 0;
  for (i = 0; i < 1000; i++) {
    for (j = four[i]; j <= 1000000; j++) {
      c[j] = min(c[j], c[j - four[i]] + 1);
    }
  }

  c_2[0] = 0;
  for (i = 0; i < 1000; i++) {
    for (j = four_2[i]; j <= 1000000; j++) {
      c_2[j] = min(c_2[j], c_2[j - four_2[i]] + 1);
    }
  }

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

    cout << c[n] << " " << c_2[n] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int i, j, n, three[1000000], four[1000000], four_2[1000000], c[1000000],
    c_2[1000000];

int main() {

  three[0] = 1;
  four[0] = 1;
  for (i = 1; i < 1000000; i++)
    three[i] = i + 1 + three[i - 1];
  for (i = 1; i < 1000000; i++)
    four[i] = three[i] + four[i - 1];

  int k = 0;
  for (i = 0; i < 1000000; i++) {
    if (four[i] % 2 == 1) {
      four_2[k] = four[i];
      k++;
    }
  }

  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    for (i = 0; i <= n; i++) {
      c[i] = 2000000;
      c_2[i] = 2000000;
    }

    c[0] = 0;
    for (i = 0; i < 1000; i++) {
      for (j = four[i]; j <= n; j++) {
        c[j] = min(c[j], c[j - four[i]] + 1);
      }
    }

    c_2[0] = 0;
    for (i = 0; i < 1000; i++) {
      for (j = four_2[i]; j <= n; j++) {
        c_2[j] = min(c_2[j], c_2[j - four_2[i]] + 1);
      }
    }
    cout << c[n] << " " << c_2[n] << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int dp[1000001], Odp[1000001];
int Tn[200], OTn[200];

int main() {
  int count = 0; // pollocks numberの生成
  for (int i = 1; i < 200; i++) {
    Tn[i - 1] = i * (i + 1) * (i + 2) / 6;
    if (Tn[i - 1] % 2 == 1) {
      OTn[count] = Tn[i - 1];
      count++;
    }
  }
  int n = 1000000;

  // 正四面体数の個数の最小値
  for (int j = 0; j <= n; j++)
    dp[j] = j;
  int k;
  for (int i = 0; i < 200; i++)
    for (int j = Tn[i]; j <= 1000000; j++) {
      if (j >= Tn[i])
        dp[j] = min(dp[j], dp[j - Tn[i]] + 1);
      k = i;
    }

  // 奇数正四面体数の個数の最小値
  for (int j = 0; j <= n; j++)
    Odp[j] = j;
  int k1;
  for (int i = 0; i <= 200; i++)
    for (int j = OTn[i]; j <= n; j++) {
      if (j >= OTn[i])
        Odp[j] = min(Odp[j], Odp[j - OTn[i]] + 1);
      k1 = i;
    }
  while (cin >> n, n)
    cout << dp[n] << ' ' << Odp[n] << endl;

  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int dp[200][1000001], Odp[200][1000001];
int Tn[200], OTn[200]; // Pollocks numberの生成

int main() {
  int count = 0;
  for (int i = 1; i < 200; i++) {
    Tn[i - 1] = i * (i + 1) * (i + 2) / 6;
    if (Tn[i - 1] % 2 == 1) {
      OTn[count] = Tn[i - 1];
      count++;
    }
  }
  int n = 1000000;

  // 正四面体数の個数の最小値
  for (int j = 0; j <= n; j++)
    dp[0][j] = j;
  int k;
  for (int i = 1; Tn[i] <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (j < Tn[i])
        dp[i][j] = dp[i - 1][j];
      else
        dp[i][j] = min(dp[i - 1][j], dp[i][j - Tn[i]] + 1);
      k = i;
    }

  // 正四面体数の個数の最小値
  for (int j = 0; j <= n; j++)
    Odp[0][j] = j;
  int k1;
  for (int i = 1; OTn[i] <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (j < OTn[i])
        Odp[i][j] = Odp[i - 1][j];
      else
        Odp[i][j] = min(Odp[i - 1][j], Odp[i][j - OTn[i]] + 1);
      k1 = i;
    }
  while (cin >> n, n)
    cout << dp[k][n] << ' ' << Odp[k1][n] << endl;

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

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int n;

int dp[2][1000010], adp[2][1000010];
int INF = 1e9;
int add[200], oadd[200];

void solve() {
  for (int i = 0; i < 2; i++) {
    fill(dp[i], dp[i] + 1000010, INF);
    fill(adp[i], adp[i] + 1000010, INF);
  }

  dp[0][0] = 0;
  for (int i = 0; i < 200; i++) {
    int nw = i % 2, nx = (i + 1) % 2;
    for (int j = 0; j <= 1000000; j++) {
      if (add[i] <= j) {
        dp[nx][j] = min(dp[nw][j], dp[nx][j - add[i]] + 1);
      } else {
        dp[nx][j] = dp[nw][j];
      }
    }
  }

  adp[0][0] = 0;
  for (int i = 0; i < 200; i++) {
    int nw = i % 2, nx = (i + 1) % 2;

    for (int j = 0; j <= 1000000; j++) {
      if (oadd[i] <= j) {
        adp[nx][j] = min(adp[nw][j], adp[nx][j - oadd[i]] + 1);
      } else {
        adp[nx][j] = adp[nw][j];
      }
    }
  }
}

void qer() {
  int ans1 = INF, ans2 = INF;
  for (int i = 0; i < 2; i++) {
    ans1 = min(ans1, dp[i][n]);
    ans2 = min(ans2, adp[i][n]);
  }
  cout << ans1 << " " << ans2 << endl;
}

int main() {
  int p = 0;
  for (int i = 0; i < 200; i++) {
    add[i] = i * (i + 1) * (i + 2) / 6;
    if (add[i] % 2 == 1)
      oadd[p++] = add[i];
  }
  solve();

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int n;

int dp[2][1000010], adp[2][1000010];
int INF = 1e9;
int add[200], oadd[200];

void solve() {
  for (int i = 0; i < 2; i++) {
    fill(dp[i], dp[i] + 1000010, INF);
    fill(adp[i], adp[i] + 1000010, INF);
  }

  dp[0][0] = 0;
  // adp[0][0] = 0;
  for (int i = 0; i < 200; i++) {
    int nw = i % 2, nx = (i + 1) % 2;
    if (add[i] > n)
      break;
    for (int j = 0; j <= n; j++) {
      if (add[i] <= j) {
        dp[nx][j] = min(dp[nw][j], dp[nx][j - add[i]] + 1);
      } else {
        dp[nx][j] = dp[nw][j];
      }
      /*
      if (add%2==0) {
              adp[nx][j] = adp[nw][j];
      } else {
              if (add <= j) {
                      adp[nx][j] = min(adp[nw][j], adp[nx][j-add] + 1);
              } else {
                      adp[nx][j] = adp[nw][j];
              }
      }
      */
    }
  }

  adp[0][0] = 0;
  for (int i = 0; i < 200; i++) {
    int nw = i % 2, nx = (i + 1) % 2;
    if (oadd[i] % 2 == 0)
      continue;
    if (oadd[i] > n)
      break;

    for (int j = 0; j <= n; j++) {
      if (oadd[i] <= j) {
        adp[nx][j] = min(adp[nw][j], adp[nx][j - oadd[i]] + 1);
      } else {
        adp[nx][j] = adp[nw][j];
      }
    }
  }

  int ans1 = INF, ans2 = INF;
  for (int i = 0; i < 2; i++) {
    ans1 = min(ans1, dp[i][n]);
    ans2 = min(ans2, adp[i][n]);
  }
  cout << ans1 << " " << ans2 << endl;
}

int main() {
  int p = 0;
  for (int i = 0; i < 200; i++) {
    add[i] = i * (i + 1) * (i + 2) / 6;
    if (add[i] % 2 == 1)
      oadd[p++] = add[i];
  }

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

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

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int i;
  int n;
  int j = 0;
  int a[202];
  int b[202];
  vector<int> t1(1000010, 0), t2(1000010, 0);
  for (i = 0; i < 200; i++) {
    a[i] = (i + 1) * (i + 2) * (i + 3) / 6;
    if (a[i] % 2 == 1) {
      b[j] = a[i];
      j++;
    }
  }
  /*cout << a[82] << b[20] << endl;
  for(i = 0; i < 200; i++){
      cout << "a[" << i << "] = " << a[i] << endl;
  }
  for(i = 0; i < 200; i++){
      cout << "b[" << i << "] = " << b[i] << endl;
  }*/

  for (i = 0; i <= 1000005; i++) {
    t1[i] = i;
  }

  for (i = 0; i <= 179; i++) {
    for (j = a[i]; j <= 1000005; j++) {
      if (t1[j] > t1[j - a[i]] + 1) {
        t1[j] = t1[j - a[i]] + 1;
      }
    }
  }

  for (i = 0; i <= 1000005; i++) {
    t2[i] = i;
  }

  for (i = 0; i <= 44; i++) {
    for (j = b[i]; j <= 1000005; j++) {
      if (t2[j] > t2[j - b[i]] + 1) {
        t2[j] = t2[j - b[i]] + 1;
      }
    }
  }

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    cout << t1[n] << " " << t2[n] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int i;
  int n;
  int j = 0;
  int a[84];
  int b[22];
  int t1[100010], t2[100010];
  for (i = 0; i < 83; i++) {
    a[i] = (i + 1) * (i + 2) * (i + 3) / 6;
    if (a[i] % 2 == 1) {
      b[j] = a[i];
      j++;
    }
  }
  // cout << a[82] << b[20] << endl;
  /*for(i = 0; i < 83; i++){
      cout << "a[i] = " << a[i] << endl;
  }
  for(i = 0; i < 21; i++){
      cout << "b[i] = " << b[i] << endl;
  }*/

  for (i = 0; i <= 100005; i++) {
    t1[i] = i;
  }

  for (i = 0; i <= 82; i++) {
    for (j = a[i]; j <= 100005; j++) {
      if (t1[j] > t1[j - a[i]] + 1) {
        t1[j] = t1[j - a[i]] + 1;
      }
    }
  }

  for (i = 0; i <= 100005; i++) {
    t2[i] = i;
  }

  for (i = 0; i <= 20; i++) {
    for (j = b[i]; j <= 100005; j++) {
      if (t2[j] > t2[j - b[i]] + 1) {
        t2[j] = t2[j - b[i]] + 1;
      }
    }
  }

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    cout << t1[n] << " " << t2[n] << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int a[1001], ta[1001], tta[1001];
int dp[1000021], dp2[1000010];
const int INF = 99999999;
int main() {
  a[1] = 1, ta[1] = 1, tta[1] = 1;
  int cnt = 1;
  for (int i = 2; i <= 1000; i++)
    a[i] = i + a[i - 1];
  for (int i = 2; i <= 1000; i++) {
    ta[i] = a[i] + ta[i - 1];
    if (ta[i] % 2 == 1)
      tta[++cnt] = ta[i];
  }

  fill(dp, dp + 1000001, INF);
  fill(dp2, dp2 + 1000001, INF);
  dp[0] = 0, dp2[0] = 0;
  for (int i = 1; i <= 200; i++) {
    for (int j = 1; j <= 1000000; j++) {
      if (j >= ta[i])
        dp[j] = min(dp[j], dp[j - ta[i]] + 1);
    } //
  }   // endfor
  for (int i = 1; i <= 100; i++) {
    for (int j = 1; j <= 1000000; j++) {
      if (j >= tta[i])
        dp2[j] = min(dp2[j], dp2[j - tta[i]] + 1);
    }
  } // endfor
  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    cout << dp[n] << " " << dp2[n] << endl;
  } // endwhile
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int a[1001], ta[1001], tta[1001];
int dp[1000021];
const int INF = 99999999;
int main() {
  a[1] = 1, ta[1] = 1, tta[1] = 1;
  int cnt = 1;
  for (int i = 2; i <= 1000; i++)
    a[i] = i + a[i - 1];
  for (int i = 2; i <= 1000; i++) {
    ta[i] = a[i] + ta[i - 1];
    if (ta[i] % 2 == 1)
      tta[++cnt] = ta[i];
  }
  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    ta[1] = 1;
    int am = 0, bm = 0;
    for (int i = 0; i < 200; i++) {
      if (n <= ta[i]) {
        am = ta[i];
        break;
      }
    }
    for (int i = 0; i < 100; i++) {
      if (n <= tta[i]) {
        bm = tta[i];
        break;
      }
    }
    fill(dp + 1, dp + 1000021, INF);
    for (int i = 0; i <= am; i++) {
      for (int j = 1; j <= n; j++) {
        if (j >= ta[i])
          dp[j] = min(dp[j], dp[j - ta[i]] + 1);
      }
    } // endfor
    cout << dp[n] << " ";
    fill(dp + 1, dp + 1000021, INF);
    for (int i = 0; i <= bm; i++) {
      for (int j = 1; j <= n; j++) {
        if (j >= tta[i])
          dp[j] = min(dp[j], dp[j - tta[i]] + 1);
      }
    } // endfor
    cout << dp[n] << endl;
  } // endwhile
  return 0;
}