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

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define loop for (;;)
#define trace(var) cerr << ">>> " << #var << " = " << var << endl;
#define all(v) begin(v), end(v)
#define pb push_back
#define inf (1e9)
#define eps (1e-9)

typedef long long Integer;
typedef long double Real;
const Real PI = acosl(-1);
typedef pair<int, int> P;

template <class S, class T>
inline ostream &operator<<(ostream &os, pair<S, T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class S, class T, class U>
inline ostream &operator<<(ostream &os, tuple<S, T, U> t) {
  return os << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t)
            << ')';
}

template <class T> inline ostream &operator<<(ostream &os, set<T> v) {
  os << "(set";
  for (T item : v)
    os << ' ' << item;
  os << ")";
  return os;
}

template <class T> inline ostream &operator<<(ostream &os, vector<T> v) {
  if (v.size() == 0) {
    return os << "(empty)";
  }
  os << v[0];
  for (int i = 1, len = v.size(); i < len; ++i)
    os << ' ' << v[i];
  return os;
}

template <class T> inline istream &operator>>(istream &is, vector<T> &v) {
  rep(i, v.size()) is >> v[i];
  return is;
}

//           ^   >  v   <
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<bool> vb;

int table[11][331];
int memo[10];

void f(int size, int depth, int sum) {
  if (size + 1 == depth) {
    table[size][sum]++;
  } else {
    rep(i, 10) {
      if (memo[i] == 0) {
        memo[i] = 1;
        f(size, depth + 1, sum + i * depth);
        memo[i] = 0;
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  rep(i, 10) {
    memset(memo, 0, sizeof(memo));
    f(i + 1, 1, 0);
  }

  int n, s;
  while (cin >> n >> s) {
    if (s > 330) {
      cout << 0 << endl;
    } else {
      cout << table[n][s] << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define loop for (;;)
#define trace(var) cerr << ">>> " << #var << " = " << var << endl;
#define all(v) begin(v), end(v)
#define pb push_back
#define inf (1e9)
#define eps (1e-9)

typedef long long Integer;
typedef long double Real;
const Real PI = acosl(-1);
typedef pair<int, int> P;

template <class S, class T>
inline ostream &operator<<(ostream &os, pair<S, T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class S, class T, class U>
inline ostream &operator<<(ostream &os, tuple<S, T, U> t) {
  return os << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t)
            << ')';
}

template <class T> inline ostream &operator<<(ostream &os, set<T> v) {
  os << "(set";
  for (T item : v)
    os << ' ' << item;
  os << ")";
  return os;
}

template <class T> inline ostream &operator<<(ostream &os, vector<T> v) {
  if (v.size() == 0) {
    return os << "(empty)";
  }
  os << v[0];
  for (int i = 1, len = v.size(); i < len; ++i)
    os << ' ' << v[i];
  return os;
}

template <class T> inline istream &operator>>(istream &is, vector<T> &v) {
  rep(i, v.size()) is >> v[i];
  return is;
}

//           ^   >  v   <
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<bool> vb;

int table[11][500];
int memo[10];

void f(int size, int depth, int sum) {
  if (size + 1 == depth) {
    table[size][sum]++;
  } else {
    rep(i, 10) {
      if (memo[i] == 0) {
        memo[i] = 1;
        f(size, depth + 1, sum + i * depth);
        memo[i] = 0;
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  rep(i, 10) {
    memset(memo, 0, sizeof(memo));
    f(i + 1, 1, 0);
  }

  int n, s;
  while (cin >> n >> s)
    cout << table[n][s] << endl;

  return 0;
}