Problem p00748 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

vector<int> nums;
vector<int> oddnums;

vector<short> memo(1000001, -1);
vector<short> oddmemo(1000001, -1);

int getans(const int num, const int atime) {
  if (memo[num] != -1) {
    return memo[num];
  } else {
    if (num == 0)
      return memo[num] = 0;
    int ans = num;
    for (int i = 0; i < nums.size(); ++i) {
      int minusnum = nums[i];
      if (minusnum > num) {
        break;
      } else if (num / minusnum > 10) {
        continue;
      }
      ans = min(ans, getans(num - minusnum, atime + 1) + 1);
    }

    return memo[num] = ans;
  }
}
int getoddans(const int num, const int atime) {
  if (oddmemo[num] != -1) {
    return oddmemo[num];
  } else {
    if (num == 0)
      return oddmemo[num] = 0;
    int ans = num;
    for (int i = 0; i < oddnums.size(); ++i) {
      int minusnum = oddnums[i];
      if (minusnum > num) {
        break;
      } else if (num / minusnum > 100) {
        continue;
      }
      ans = min(ans, getoddans(num - minusnum, atime + 1) + 1);
    }
    return oddmemo[num] = ans;
  }
}
int main() {
  for (int i = 1; i < 190; ++i) {
    nums.push_back(i * (i + 1) * (i + 2) / 6);
    if (((i * (i + 1) * (i + 2)) / 6) % 2) {

      oddnums.push_back((i * (i + 1) * (i + 2)) / 6);
    }
  }

  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;
    int normalans = getans(n, 0);
    ;
    int oddans = getoddans(n, 0);

    cout << normalans << " " << oddans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

vector<int> nums;
vector<int> oddnums;

vector<vector<short>> memo(100001, vector<short>(190, -1));
vector<vector<short>> oddmemo(100001, vector<short>(50, -1));

int getans(const int num, const int used, const int atime) {
  if (memo[num][used] != -1) {
    return memo[num][used];
  } else {
    if (num == 0)
      return memo[num][used] = 0;
    if (atime > 10)
      return atime;
    int ans = num;
    for (int i = 0; i <= used; ++i) {
      int minusnum = nums[i];
      if (minusnum > num) {
        break;
      } else if (num / minusnum > 10) {
        continue;
      }
      ans = min(ans, getans(num - minusnum, i, atime + 1) + 1);
    }

    return memo[num][used] = ans;
  }
}
int getoddans(const int num, const int used, const int atime) {
  if (oddmemo[num][used] != -1) {
    return oddmemo[num][used];
  } else {
    if (num == 0)
      return oddmemo[num][used] = 0;
    if (atime > 100)
      return atime;
    int ans = num;
    for (int i = 0; i <= min(int(oddnums.size()), used); ++i) {
      int minusnum = oddnums[i];
      if (minusnum > num) {
        break;
      } else if (num / minusnum > 100) {
        continue;
      }
      ans = min(ans, getoddans(num - minusnum, i, atime + 1) + 1);
    }

    return oddmemo[num][used] = ans;
  }
}
int main() {
  for (int i = 1; i < 190; ++i) {
    nums.push_back(i * (i + 1) * (i + 2) / 6);
    if (((i * (i + 1) * (i + 2)) / 6) % 2) {

      oddnums.push_back((i * (i + 1) * (i + 2)) / 6);
    }
  }

  while (1) {
    int n;
    cin >> n;
    if (!n)
      break;
    int normalans = getans(n, 189, 0);
    ;
    int oddans = getoddans(n, 47, 0);

    cout << normalans << " " << oddans << endl;
  }
  return 0;
}