alexjercan/bugnet huggingface dataset:
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int tbl1[1000000], tbl2[1000000];
int main() {
  int n = 1000000;
  int c = 0;
  for (int i = 1; i < n; ++i)
    tbl1[i] = tbl2[i] = i;
  for (int i = 2;; ++i) {
    int t = i * (i + 1) * (i + 2) / 6;
    if (t >= n)
      break;
    for (int j = 0; j + t < n; ++j) {
      if (t % 2)
        tbl2[j + t] = min(tbl2[j + t], tbl2[j] + 1);
      tbl1[j + t] = min(tbl1[j + t], tbl1[j] + 1);
    }
  }
  while (cin >> n, n)
    cout << tbl1[n] << " " << tbl2[n] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int tbl1[1000001];
int tbl2[1000001];
int tet(int x) { return x * (x + 1) * (x + 2) / 6; }
int solve1(int n) {
  if (n < 0)
    return 1000;
  if (n == 0)
    return 0;
  if (tbl1[n])
    return tbl1[n];
  int ret = 1000;
  for (int i = 1; tet(i) <= n; ++i)
    ret = min(ret, 1 + solve1(n - tet(i)));
  return tbl1[n] = ret;
}
int solve2(int n) {
  if (n < 0)
    return 1000;
  if (n == 0)
    return 0;
  if (tbl2[n])
    return tbl2[n];
  int ret = 1000;
  for (int i = 1; tet(i) <= n; ++i)
    if (tet(i) % 2)
      ret = min(ret, 1 + solve2(n - tet(i)));
  return tbl2[n] = ret;
}

int main() {
  int n;
  while (cin >> n, n) {
    cout << solve1(n) << " " << solve2(n) << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

void append(int t, int n, int table[]) {
  table[t] = 1;
  for (int i = 0; i <= n - t; i++) {
    if (table[i] < 0) {
      continue;
    }
    if (table[i + t] < 0) {
      table[i + t] = table[i] + 1;
    } else {
      table[i + t] = min(table[i] + 1, table[i + t]);
    }
  }
}

int main() {
  int n;
  int dp[1000000];
  int dp_odd[1000000];
  for (int i = 0; i < 1000000; i++) {
    dp[i] = -1;
    dp_odd[i] = -1;
  }
  for (int i = 0; true; i++) {
    int t = i * (i + 1) * (i + 2) / 6;
    if (t > 1000000) {
      break;
    }
    append(t, 1000000, dp);
    if (t % 2 == 1) {
      append(t, 1000000, dp_odd);
    }
  }
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    cout << dp[n] << ' ' << dp_odd[n] << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

void append(int t, int n, int table[]) {
  table[t] = 1;
  for (int i = 0; i <= n - t; i++) {
    if (table[i] < 0) {
      continue;
    }
    if (table[i + t] < 0) {
      table[i + t] = table[i] + 1;
    } else {
      table[i + t] = min(table[i] + 1, table[i + t]);
    }
  }
}

int main() {
  int n;
  int dp[1000000];
  int dp_odd[1000000];
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i <= n; i++) {
      dp[i] = -1;
      dp_odd[i] = -1;
    }
    for (int i = 0; true; i++) {
      int t = i * (i + 1) * (i + 2) / 6;
      if (t > n) {
        break;
      }
      append(t, n, dp);
      if (t % 2 == 1) {
        append(t, n, dp_odd);
      }
    }
    cout << dp[n] << ' ' << dp_odd[n] << endl;
  }
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  const int N = 999999;

  vector<int> num1(N + 1, -1);
  vector<int> num2(N + 1, -1);
  num1[0] = 0;
  num2[0] = 0;
  for (int i = 1;; ++i) {
    int tmp = i * (i + 1) * (i + 2) / 6;
    if (tmp > N)
      break;
    for (int j = 0; j + tmp <= N; ++j) {
      if (num1[j] >= 0 &&
          (num1[j + tmp] == -1 || num1[j] + 1 < num1[j + tmp])) {
        num1[j + tmp] = num1[j] + 1;
      }
    }
    if (tmp % 2 == 1) {
      for (int j = 0; j + tmp <= N; ++j) {
        if (num2[j] >= 0 &&
            (num2[j + tmp] == -1 || num2[j] + 1 < num2[j + tmp])) {
          num2[j + tmp] = num2[j] + 1;
        }
      }
    }
  }

  for (;;) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    cout << num1[n] << ' ' << num2[n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

void solution(int n) {
  vector<int> num(n + 1, -1);
  num[0] = 0;
  for (int i = 1;; ++i) {
    int tmp = i * (i + 1) * (i + 2) / 6;
    if (tmp > n)
      break;
    for (int j = 0; j + tmp <= n; ++j) {
      if (num[j] >= 0 && (num[j + tmp] == -1 || num[j] + 1 < num[j + tmp])) {
        num[j + tmp] = num[j] + 1;
      }
    }
  }
  cout << num[n] << ' ';

  num.assign(n + 1, -1);
  num[0] = 0;
  for (int i = 1;; ++i) {
    int tmp = i * (i + 1) * (i + 2) / 6;
    if (tmp > n)
      break;
    if (tmp % 2 == 0)
      continue;
    for (int j = 0; j + tmp <= n; ++j) {
      if (num[j] >= 0) {
        num[j + tmp] = num[j] + 1;
      }
    }
  }
  cout << num[n] << endl;
}

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    solution(n);
  }

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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

int a[201];
int dp1[1000001], dp2[1000001];
int main() {
  FOR(i, 1, 201) { a[i - 1] = i * (i + 1) * (i + 2) / 6; }
  int n;
  while (cin >> n, n) {
    rep(i, n + 1) dp1[i] = dp2[i] = 1000100010;
    dp1[n] = 0, dp2[n] = 0;
    rep(i, 200) for (int j = n; j >= a[199 - i]; --j) {
      dp1[j - a[199 - i]] = min(dp1[j - a[199 - i]], dp1[j] + 1);
      if (a[199 - i] % 2 == 1)
        dp2[j - a[199 - i]] = min(dp2[j - a[199 - i]], dp2[j] + 1);
    }
    cout << dp1[0] << " " << dp2[0] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

int a[201];
int dp1[1000001], dp2[1000001];
int main() {
  FOR(i, 1, 201) { a[i - 1] = i * (i + 1) * (i + 2) / 6; }
  int n;
  while (cin >> n, n) {
    rep(i, n + 1) dp1[i] = dp2[i] = 1000100010;
    dp1[n] = 0, dp2[n] = 0;
    rep(i, 200) for (int j = n; j >= 0; --j) {
      if (j >= a[199 - i])
        dp1[j - a[199 - i]] = min(dp1[j - a[199 - i]], dp1[j] + 1);
      if (j >= a[199 - i] && a[199 - i] % 2 == 1)
        dp2[j - a[199 - i]] = min(dp2[j - a[199 - i]], dp2[j] + 1);
    }
    cout << dp1[0] << " " << dp2[0] << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int dp[500];
int dp1[11111500];
int dp2[11111100];
int main() {
  dp[1] = 1;
  for (int i = 2; i < 210; i++) {
    dp[i] = dp[i - 1] + i;
  }
  for (int i = 2; i < 210; i++) {
    dp[i] = dp[i - 1] + dp[i];
  }
  // fill(dp,dp+400,0);
  fill(dp1, dp1 + 1111100, 99999999);
  fill(dp2, dp2 + 1111100, 99999999);
  dp1[0] = 0;
  dp2[0] = 0;
  for (int i = 1; i < 210; i++) {
    int now = dp[i];
    for (int k = now; k < 1100000; k++) {
      if (dp1[k] > dp1[k - now] + 1) {
        dp1[k] = dp1[k - now] + 1;
      }
    }
  }
  for (int i = 1; i < 300; i++) {
    int now = dp[i];
    if (now % 2 == 0)
      continue;
    for (int k = now; k < 1100000; k++) {
      if (dp2[k] > dp2[k - now] + 1)
        dp2[k] = dp2[k - now] + 1;
    }
  }
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    cout << dp1[n] << " " << dp2[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int dp[500];
int dp1[11111500];
int dp2[11111100];
int main() {
  dp[1] = 1;
  for (int i = 2; i < 210; i++) {
    dp[i] = dp[i - 1] + i;
  }
  for (int i = 2; i < 210; i++) {
    dp[i] = dp[i - 1] + dp[i];
  }
  // fill(dp,dp+400,0);
  fill(dp1, dp1 + 1111100, 9999999999);
  fill(dp2, dp2 + 1111100, 9999999999);
  dp1[0] = 0;
  dp2[0] = 0;
  for (int i = 1; i < 210; i++) {
    int now = dp[i];
    for (int k = now; k < 1100000; k++) {
      if (dp1[k] > dp1[k - now] + 1) {
        dp1[k] = dp1[k - now] + 1;
      }
    }
  }
  for (int i = 1; i < 300; i++) {
    int now = dp[i];
    if (now % 2 == 0)
      continue;
    for (int k = now; k < 1100000; k++) {
      if (dp2[k] > dp2[k - now] + 1)
        dp2[k] = dp2[k - now] + 1;
    }
  }
  int n;
  while (1) {
    cin >> n;
    cout << dp1[n] << " " << dp2[n] << endl;
  }
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  const int N = 1000001;
  vector<int> full(N);
  vector<int> odd(N);
  for (int i = 0; i < N; i++)
    full[i] = i;
  for (int i = 0; i < N; i++)
    odd[i] = i;
  for (int n = 2;; n++) {
    const int t = (n * (n + 1) * (n + 2)) / 6;
    if (t >= N)
      break;
    for (int i = 0; i + t < N; i++) {
      const int k = i + t;
      if (full[i] + 1 < full[k])
        full[k] = full[i] + 1;
      if (t & 1) {
        if (odd[i] + 1 < odd[k])
          odd[k] = odd[i] + 1;
      }
    }
  }

  for (int t = 1;; t++) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    cout << full[n] << " " << odd[n] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
  const int N = 100001;
  vector<int> full(N);
  vector<int> odd(N);
  for (int i = 0; i < N; i++)
    full[i] = i;
  for (int i = 0; i < N; i++)
    odd[i] = i;
  for (int n = 2;; n++) {
    const int t = (n * (n + 1) * (n + 2)) / 6;
    if (t >= N)
      break;
    for (int i = 0; i + t < N; i++) {
      const int k = i + t;
      if (full[i] + 1 < full[k])
        full[k] = full[i] + 1;
      if (t & 1) {
        if (odd[i] + 1 < odd[k])
          odd[k] = odd[i] + 1;
      }
    }
  }

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

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

int main() {
  int num[1000010];
  int num2[1000010];
  vector<int> v;
  for (int i = 0; i < 100000; i++) {
    int m = i * (i + 1) * (i + 2) / 6;
    if (1000000 <= m)
      break;
    v.push_back(m);
  }
  for (int i = 0; i < 1000010; i++)
    num[i] = 10e8;
  for (int i = 0; i < 1000010; i++)
    num2[i] = 10e8;
  num[0] = 0;
  num2[0] = 0;
  for (int j = 0; j < 1000010; j++) {
    for (int i = 0; i < v.size(); i++) {
      int m = i * (i + 1) * (i + 2) / 6;
      if (1000010 <= m + j)
        continue;
      num[j + m] = min(num[j] + 1, num[j + m]);

      if (m == 0)
        continue;
      if (m % 2 == 0)
        continue;
      num2[j + m] = min(num2[j] + 1, num2[j + m]);
    }
  }
  int n;
  while (cin >> n, n) {
    cout << num[n] << " " << num2[n] << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int num[100010];
  for (int i = 0; i < 100010; i++)
    num[i] = 10e8;
  num[0] = 0;
  for (int j = 0; j < 100010; j++) {
    for (int i = 1; i < 1000; i++) {
      int m = i * (i + 1) * (i + 2) / 6;
      if (10010 <= i * (i + 1) * (i + 2) / 6 + j)
        continue;
      num[j + m] = min(num[j] + 1, num[j + m]);
    }
  }
  int num2[100010];
  for (int i = 0; i < 100010; i++)
    num2[i] = 10e8;
  num2[0] = 0;
  for (int j = 0; j < 100010; j++) {
    for (int i = 1; i < 1010; i++) {
      int m = i * (i + 1) * (i + 2) / 6;
      if (m == 0)
        continue;
      if (m % 2 == 0)
        continue;
      if (10010 <= i * (i + 1) * (i + 2) / 6 + j)
        continue;
      num2[j + m] = min(num2[j] + 1, num2[j + m]);
    }
  }
  int n;
  while (cin >> n, n) {
    cout << num[n] << " " << num2[n] << endl;
  }
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int num[1000010], num2[1000010];
  for (int i = 0; i < 1000010; i++)
    num[i] = num2[i] = 10e8;
  num[0] = num2[0] = 0;
  for (int j = 0; j < 1000010; j++) {
    for (int i = 0; i < 1200; i++) {
      int m = i * (i + 1) * (i + 2) / 6;
      if (1000010 <= m + j)
        continue;
      num[j + m] = min(num[j] + 1, num[j + m]);

      if (m == 0)
        continue;
      if (m % 2 == 0)
        continue;
      num2[j + m] = min(num2[j] + 1, num2[j + m]);
    }
  }
  int n;
  while (cin >> n, n) {
    cout << num[n] << " " << num2[n] << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int num[1000010], num2[1000010];
  for (int i = 0; i < 1000010; i++)
    num[i] = num2[i] = 10e8;
  num[0] = num2[0] = 0;
  for (int j = 0; j < 1000010; j++) {
    for (int i = 0; i < 1500; i++) {
      int m = i * (i + 1) * (i + 2) / 6;
      if (1000010 <= m + j)
        continue;
      num[j + m] = min(num[j] + 1, num[j + m]);

      if (m == 0)
        continue;
      if (m % 2 == 0)
        continue;
      num2[j + m] = min(num2[j] + 1, num2[j + m]);
    }
  }
  int n;
  while (cin >> n, n) {
    cout << num[n] << " " << num2[n] << endl;
  }
}
Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int all[1000001];
int odd[1000001];

int const INF = 1 << 29;

int main() {

  fill(all, all + 1000001, INF);
  fill(odd, odd + 1000001, INF);

  all[0] = odd[0] = 0;

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

  int N;
  while (cin >> N && N) {
    cout << all[N] << ' ' << odd[N] << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int all[1000001];
int odd[1000001];

int const INF = 1 << 29;

int main() {

  fill(all, all + 1000001, INF);
  fill(odd, odd + 1000001, INF);

  all[0] = odd[0] = 0;

  for (int i = 1;; i++) {
    int n = i * (i + 1) * (i + 2);
    for (int j = n; j <= 1000000; j++) {
      all[j] = min(all[j - n] + 1, all[j]);
      if (n % 2) {
        odd[j] = min(odd[j - n] + 1, odd[j]);
      }
    }
  }

  int N;
  while (cin >> N && N) {
    cout << all[N] << ' ' << odd[N] << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

int const MAX = 1000001;
int const INF = 1 << 29;
int dpa[MAX + 1];
int dpo[MAX + 1];

int main() {

  fill(dpa, dpa + MAX, INF);
  fill(dpo, dpo + MAX, INF);

  dpa[0] = dpo[0] = 0;

  for (int i = 1;; i++) {
    int n = i * (i + 1) * (i + 2) / 6;
    if (n > MAX)
      break;
    for (int j = n; j <= MAX; j++) {
      dpa[j] = min(dpa[j], dpa[j - n] + 1);
      if (n % 2) {
        dpo[j] = min(dpo[j], dpo[j - n] + 1);
      }
    }
  }

  for (int N; cin >> N && N;) {
    cout << dpa[N] << ' ' << dpo[N] << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int const MAX = 1000000;
int const INF = 1 << 29;
int dpa[MAX + 1];
int dpo[MAX + 1];

int main() {

  fill(dpa, dpa + MAX, INF);
  fill(dpo, dpo + MAX, INF);

  dpa[0] = dpo[0] = 0;

  for (int i = 1;; i++) {
    int n = i * (i + 1) * (i + 2) / 6;
    for (int j = n; j <= MAX; j++) {
      dpa[j] = min(dpa[j], dpa[j - n] + 1);
      if (n % 2) {
        dpo[j] = min(dpo[j], dpo[j - n] + 1);
      }
    }
  }

  for (int N; cin >> N && N;) {
    cout << dpa[N] << ' ' << dpo[N] << endl;
  }

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

#include <stdio.h>
#include <vector>
std::vector<int> t, o;
const int N = 1000000, V = 1 << 9;
int a[N], b[N];
int main() {
  int i, j, n;
  for (i = 1; i < N; ++i)
    a[i] = b[i] = V;
  for (i = 1; n = (i * (i + 1) * (i + 2)) / 6, n < N; ++i)
    if (a[n] = 1, t.push_back(n), n & 1)
      b[n] = 1, o.push_back(n);
  for (i = t.size() - 1; i >= 0; --i) {
    a[t[i]] = 1;
    for (j = t[i]; j + t[i] < N; ++j)
      if (a[j] + 1 < a[j + t[i]])
        a[j + t[i]] = a[j] + 1;
  }
  for (i = o.size() - 1; i >= 0; --i) {
    b[o[i]] = 1;
    for (j = o[i]; j + o[i] < N; ++j)
      if (b[j] + 1 < b[j + o[i]])
        b[j + o[i]] = b[j] + 1;
  }
  while (scanf("%d", &n), n)
    printf("%d %d\\n", a[n], b[n]);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <vector>
std::vector<int> t, o;
const int N = 100000, V = 1 << 15;
int a[N], b[N];
int main() {
  int i, j, n;
  for (i = 1; i < N; ++i)
    a[i] = b[i] = V;
  for (i = 1; n = (i * (i + 1) * (i + 2)) / 6, n < N; ++i)
    if (t.push_back(n), n & 1)
      o.push_back(n);
  for (i = 0; i < t.size(); ++i) {
    a[t[i]] = 1;
    for (j = 0; j + t[i] < N; ++j)
      if (a[j] - V && a[j] > 5)
        break;
      else if (a[j] + 1 < a[j + t[i]])
        a[j + t[i]] = a[j] + 1;
  }
  for (i = 0; i < o.size(); ++i) {
    b[o[i]] = 1;
    for (j = 0; j + o[i] < N; ++j)
      if (b[j] - V && b[j] > 37)
        break;
      else if (b[j] + 1 < b[j + o[i]])
        b[j + o[i]] = b[j] + 1;
  }
  while (scanf("%d", &n), n)
    printf("%d %d\\n", a[n], b[n]);
  return 0;
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  //??£?????¢?????°??¨????????????????\\???°??????????????????????????¨??£??????????????¨???
  int sq[200] = {0};
  int oddsq[200] = {0};
  //???????????????index?????????
  int index = 0;
  int indexODD = 0;
  // dp???????????¨??????
  int INF = 2000000;

  for (int i = 0; (i + 1) * (i + 2) * (i + 3) / 6 <= 1000000; ++i) {
    sq[i] = (i + 1) * (i + 2) * (i + 3) / 6;
    if (sq[i] % 2 == 1)
      oddsq[indexODD++] = sq[i];
    // printf("%3d :%7d\\n",i, sq[i]);
    index = i + 1;
  }
  // printf("index= %d, inODD = %d\\n", index, indexODD);

  // solve

  // dpA[i]:=??°i?????£?????¢?????°????????¨????????¨?????¨?????????????????£?????¢?????°?????°???????°????
  int dpA[1000001];
  fill(dpA, dpA + 1000001, INF);
  dpA[0] = 0;

  for (int i = 0; i < 1000001; ++i) {
    for (int j = 0; j < index; ++j) {
      if (i + sq[j] < 1000001)
        dpA[i + sq[j]] = min(dpA[i + sq[j]], dpA[i] + 1);
      else
        break;
    }
  }

  // dpB[i]:=??°i?????£?????¢?????°????????¨????????¨?????¨???????????????????\\???°????????£?????¢?????°?????°???????°????
  int dpB[1000001];
  fill(dpB, dpB + 1000001, INF);
  dpB[0] = 0;

  for (int i = 0; i < 1000001; ++i) {
    for (int j = 0; j < indexODD; ++j) {
      if (i + oddsq[j] < 1000001)
        dpB[i + oddsq[j]] = min(dpB[i + oddsq[j]], dpB[i] + 1);
      else
        break;
    }
  }

  while (1) {
    int n;
    scanf(" %d", &n);
    if (n == 0)
      break;
    printf("%d %d\\n", dpA[n], dpB[n]);
  }
}

Error: TLE

Fixed submission:

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

int main() {
  //??£?????¢?????°??¨????????????????\\???°??????????????????????????¨??£??????????????¨???
  int sq[200] = {0};
  int oddsq[200] = {0};
  //???????????????index?????????
  int index = 0;
  int indexODD = 0;
  // dp???????????¨??????
  int INF = 2000000;

  for (int i = 0; (i + 1) * (i + 2) * (i + 3) / 6 <= 1000000; ++i) {
    sq[i] = (i + 1) * (i + 2) * (i + 3) / 6;
    if (sq[i] % 2 == 1)
      oddsq[indexODD++] = sq[i];
    // printf("%3d :%7d\\n",i, sq[i]);
    index = i + 1;
  }
  // printf("index= %d, inODD = %d\\n", index, indexODD);

  // solve
  while (1) {
    int n;
    scanf(" %d", &n);
    if (n == 0)
      break;

    // dp[i]:=??°i?????£?????¢?????°????????¨????????¨?????¨?????????????????£?????¢?????°?????°???????°????

    int dp[1000001];
    fill(dp, dp + n + 1, INF);
    dp[0] = 0;

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < index; ++j) {
        if (i + sq[j] <= n)
          dp[i + sq[j]] = min(dp[i + sq[j]], dp[i] + 1);
        else
          break;
      }
    }
    int ans1 = dp[n];

    //?\\???°?????????????????????????????¨??????
    fill(dp, dp + n + 1, INF);
    dp[0] = 0;

    for (int i = 0; i <= n; ++i) {
      for (int j = 0; j < indexODD; ++j) {
        if (i + oddsq[j] <= n)
          dp[i + oddsq[j]] = min(dp[i + oddsq[j]], dp[i] + 1);
        else
          break;
      }
    }
    int ans2 = dp[n];

    printf("%d %d\\n", ans1, ans2);
  }
}
Problem p00748 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> smt(1, 0);
  vector<int> ksmt(1, 0);
  int a;
  for (int i = 1; i < 10000; i++) {
    a = i * (i + 1) * (i + 2) / 6;
    smt.push_back(a);
    if (a % 2 == 1)
      ksmt.push_back(a);
    if (a > 1000000)
      break;
    // cout << a << endl;
  }
  // cout <<smt.size()<<" "<<ksmt.size()<<endl;
  int dp[2][1000001] = {};
  // cout <<"2"<<endl;
  //
  for (int i = 1; i <= 1000000; i++) {
    dp[0][i] = i;
    dp[1][i] = i;
  }
  // all
  for (int i = 1; i < smt.size(); i++) {
    for (int j = 1; j <= 1000000; j++) {
      if (smt[i] > j)
        dp[0][j] = dp[0][j];
      else {
        dp[0][j] = min(dp[0][j], dp[0][j - smt[i]] + 1);
      }
      // cout <<dp[k][j]<<" ";
    }
  }
  // kisuu
  for (int i = 1; i < ksmt.size(); i++) {
    for (int j = 1; j <= 1000000; j++) {
      if (ksmt[i] > j)
        dp[1][j] = dp[1][j];
      else {
        dp[1][j] = min(dp[1][j], dp[1][j - ksmt[i]] + 1);
      }
    }
  }
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    cout << dp[0][n] << " " << dp[1][n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> smt(1, 0);
  vector<int> ksmt(1, 0);
  int a;
  for (int i = 1; i < 10000; i++) {
    a = i * (i + 1) * (i + 2) / 6;
    smt.push_back(a);
    if (a % 2 == 1)
      ksmt.push_back(a);
    if (a > 1000000)
      break;
    // cout << a << endl;
  }
  while (1) {
    // cout <<smt.size()<<" "<<ksmt.size()<<endl;
    int dp[2][1000001] = {};
    // cout <<"2"<<endl;
    int n;
    cin >> n;
    int m = 0, k = 1;
    if (n == 0)
      break;
    //
    for (int i = 1; i <= n; i++) {
      dp[0][i] = i;
    }
    // all
    for (int i = 1; i < smt.size(); i++) {
      if (smt[i] > n) {
        cout << dp[m][n] << " ";
        break;
      }
      for (int j = 1; j <= n; j++) {
        if (smt[i] > j)
          dp[k][j] = dp[m][j];
        else {
          dp[k][j] = min(dp[m][j], dp[k][j - smt[i]] + 1);
        }
        // cout <<dp[k][j]<<" ";
      }
      swap(m, k);
    }
    // reset
    for (int i = 1; i <= n; i++) {
      dp[0][i] = i;
    }
    m = 0, k = 1;
    // kisuu
    for (int i = 1; i < ksmt.size(); i++) {
      if (ksmt[i] > n) {
        cout << dp[m][n] << endl;
        break;
      }
      for (int j = 1; j <= n; j++) {
        if (ksmt[i] > j)
          dp[k][j] = dp[m][j];
        else {
          dp[k][j] = min(dp[m][j], dp[k][j - ksmt[i]] + 1);
        }
      }
      swap(m, k);
    }
  }
  return 0;
}