Problem p00070 (C++)

Buggy submission (status: 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];
bool used[10];

void search(int len, int d, int sum) {
  if (len == d)
    table[len][sum]++;
  else {
    rep(i, 10) {
      if (used[i])
        continue;
      used[i] = true;
      search(len, d + 1, sum + i * (d + 1));
      used[i] = false;
    }
  }
}

void dp(int len) {
  rep(i, 10) used[i] = false;
  search(len, 0, 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) {
    trace(i + 1);
    dp(i + 1);
  }

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

  return 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][331];
bool used[10];

void search(int len, int d, int sum) {
  if (len == d)
    table[len][sum]++;
  else {
    rep(i, 10) {
      if (used[i])
        continue;
      used[i] = true;
      search(len, d + 1, sum + i * (d + 1));
      used[i] = false;
    }
  }
}

void dp(int len) {
  rep(i, 10) used[i] = false;
  search(len, 0, 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) { dp(i + 1); }

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

  return 0;
}