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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

int main() {
  const int N = 10;

  int dp[1 << N][331] = {};
  int res = 0;
  REP(i, N) { dp[1 << i][i] = 1; }
  REP(S, 1 << N) {
    vector<int> se;
    REP(j, N)
    if ((S >> j) & 1) {
      se.push_back(j);
      // cout << j << " ";
    }
    FOR(it, se) {
      REP(i, 331) {
        if (i + (*it) * se.size() >= 331)
          break;
        dp[S][i + (*it) * se.size()] += dp[S - (1 << *it)][i];
      }
    }
    // REP(i,331) {
    //   if (dp[S][i])cout << i << " ";
    // }cout << endl;
  }
  int table[11][331] = {};
  for (int i = 1; i <= N; ++i) {
    int comb = (1 << i) - 1;
    while (comb < 1 << 10) {
      REP(j, 331) { table[i][j] += dp[comb][j]; }

      int x = comb & -comb, y = comb + x;
      comb = ((comb & ~y) / x >> 1) | y;
    }
    // if (i == 3) {
    //   REP(j,331) {
    //     cout << table[i][j] << endl;
    //   }
    // }
    // cout << table[i][10] << endl;
  }

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

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1 << 29;

int main() {
  const int N = 10;

  int dp[1 << N][331] = {};
  int res = 0;
  REP(i, N) { dp[1 << i][i] = 1; }
  REP(S, 1 << N) {
    vector<int> se;
    REP(j, N)
    if ((S >> j) & 1) {
      se.push_back(j);
      // cout << j << " ";
    }
    FOR(it, se) {
      REP(i, 331) {
        if (i + (*it) * se.size() >= 331)
          break;
        dp[S][i + (*it) * se.size()] += dp[S - (1 << *it)][i];
      }
    }
    // REP(i,331) {
    //   if (dp[S][i])cout << i << " ";
    // }cout << endl;
  }
  int table[11][331] = {};
  for (int i = 1; i <= N; ++i) {
    int comb = (1 << i) - 1;
    while (comb < 1 << 10) {
      REP(j, 331) { table[i][j] += dp[comb][j]; }

      int x = comb & -comb, y = comb + x;
      comb = ((comb & ~y) / x >> 1) | y;
    }
    // if (i == 3) {
    //   REP(j,331) {
    //     cout << table[i][j] << endl;
    //   }
    // }
    // cout << table[i][10] << endl;
  }

  int n, s;
  while (cin >> n >> s) {
    if (n < 0 || n > 10 || s < 0 || s >= 331)
      cout << 0 << endl;
    cout << table[n][s] << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

// 2011/05/21 Tazoe

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

const int MAX = 1 * 0 + 2 * 1 + 3 * 2 + 4 * 3 * 5 * 4 + 6 * 5 + 7 * 6 + 8 * 7 +
                9 * 8 + 10 * 9;

int cnt[10][MAX + 1];

void prm(int k[10], int r, int &sum) {
  if (r >= 10)
    return;

  for (int i = r; i < 10; i++) {
    int tmp = k[i];
    k[i] = k[r];
    k[r] = tmp;
    sum += (r + 1) * k[r];
    cnt[r][sum]++;
    prm(k, r + 1, sum);
    sum -= (r + 1) * k[r];
    k[r] = k[i];
    k[i] = tmp;
  }
}

int main() {
  int k[10];
  for (int i = 0; i < 10; i++)
    k[i] = i;

  int sum = 0;
  prm(k, 0, sum);

  while (!cin.eof()) {
    string str;
    getline(cin, str);
    if (str.empty())
      continue;

    istringstream ist(str);
    int n, s;
    ist >> n >> s;

    if (s > MAX)
      cout << 0 << endl;
    else
      cout << cnt[n - 1][s] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

// 2011/05/21 Tazoe

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

void prm(int k[10], int r, int n, int s, int &cnt, int &sum) {
  if (r >= n) {
    if (sum == s)
      cnt++;
    return;
  }

  for (int i = r; i < 10; i++) {
    int tmp = k[i];
    for (int j = i; j > r; j--)
      k[j] = k[j - 1];
    k[r] = tmp;
    sum += (n - r) * k[r];
    if (sum <= s)
      prm(k, r + 1, n, s, cnt, sum);
    sum -= (n - r) * k[r];
    for (int j = r + 1; j <= i; j++)
      k[j - 1] = k[j];
    k[i] = tmp;
  }
}

int main() {
  int MAX =
      2 * 1 + 3 * 2 + 4 * 3 * 5 * 4 + 6 * 5 + 7 * 6 + 8 * 7 + 9 * 8 + 10 * 9;

  while (!cin.eof()) {
    string str;
    getline(cin, str);
    if (str.empty())
      continue;

    istringstream ist(str);
    int n, s;
    ist >> n >> s;

    if (s > MAX) {
      cout << 0 << endl;
      continue;
    }

    int k[10];
    for (int i = 0; i < 10; i++)
      k[i] = 9 - i;

    int cnt = 0;
    int sum = 0;
    prm(k, 0, n, s, cnt, sum);

    cout << cnt << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
int dp[11][331];
void rec(int bit, int d, int s) {
  dp[d][s]++;
  for (int i = 0; i < 10; i++) {
    if (bit & (1 << i))
      rec(bit & ~(1 << i), d + 1, s + i * (d + 1));
  }
}
int main() {
  int n, s;
  rec((1 << 10) - 1, 0, 0);
  while (cin >> n >> s) {
    if (s > 330)
      cout << 0 << endl;
    else
      cout << dp[n][s] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
int kaijou(int w) {
  if (w == 0)
    return 1;
  else
    return kaijou(w - 1) * w;
}
int main() {
  vector<int> vec;
  for (int i = 0; i < 10; i++) {
    vec.pb(i);
  }
  int n, s;
  int k7 = kaijou(7);
  while (scanf("%d %d", &n, &s) != EOF) {
    int ans = 0;
    SORT(vec);
    int t = 0;
    do {
      if (t != k7) {
        t++;
        continue;
      }
      int k = 0;
      for (int i = 0; i < n; i++) {
        k += vec[i] * (i + 1);
      }
      if (k == s)
        ans++;
      t = 0;
    } while (next_permutation(vec.begin(), vec.end()));
    cout << ans << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
void dfs(std::vector<int> &arr, std::vector<std::vector<int>> &memo, int n = 0,
         int s = 0) {
  if (n > 10)
    return;
  if (n != 0)
    ++memo[n - 1][s];
  for (auto i = n; i < 10; ++i) {
    auto temp = arr[i];
    arr[i] = arr[n];
    arr[n] = temp;
    dfs(arr, memo, n + 1, s + temp * (n + 1));
    arr[n] = arr[i];
    arr[i] = temp;
  }
}
int f(int n, int s) {
  static std::vector<std::vector<int>> memo(10, std::vector<int>(331, 0));
  static bool is_initialized = false;
  if (!is_initialized) {
    std::vector<int> arr(10);
    for (auto i = 0; i < 10; ++i)
      arr[i] = i;
    dfs(arr, memo);
    is_initialized = true;
  }
  if (0 <= s && s <= 330 && 1 <= n && n <= 10)
    return memo[n - 1][s];
  else
    return 0;
}
int main() {
  int n, s;
  while (std::cin >> n >> s) {
    std::cout << f(n, s) << std::endl;
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
void dfs(std::vector<int> &arr, std::vector<std::vector<int>> &memo, int n = 0,
         int s = 0) {
  if (n == 10)
    return;
  ++memo[n][s];
  for (auto i = n; i < 10; ++i) {
    auto temp = arr[i];
    arr[i] = arr[n];
    arr[n] = temp;
    dfs(arr, memo, n + 1, s + temp * (n + 1));
    arr[n] = arr[i];
    arr[i] = temp;
  }
}
int f(int n, int s) {
  static std::vector<std::vector<int>> memo(10, std::vector<int>(331, 0));
  static bool is_initialized = false;
  if (!is_initialized) {
    std::vector<int> arr(10);
    for (auto i = 0; i < 10; ++i)
      arr[i] = i;
    dfs(arr, memo);
    is_initialized = true;
  }
  if (0 <= s && s < 331 && memo[n][s] >= 0)
    return memo[n][s];
  return 0;
}
int main() {
  int n, s;
  while (std::cin >> n >> s) {
    std::cout << f(n, s) << std::endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int memo[300][10][2048];

int dfs(int st, int depth, int N, int S, int used) {
  if (depth == N) {
    if (st == S)
      return 1;
    else
      return 0;
  }

  int &ans = memo[st][depth][used];
  if (ans >= 0)
    return ans;

  ans = 0;
  for (int i = 0; i < 10; ++i) {
    if (used & (1 << i))
      continue;
    ans += dfs(st + i * (depth + 1), depth + 1, N, S, used | (1 << i));
  }
  return ans;
}

int main() {
  int N, S;
  while (cin >> N >> S) {
    memset(memo, -1, sizeof(memo));
    cout << dfs(0, 0, N, S, 0) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int dfs(int st, int depth, int N, int S, int *arr) {
  if (depth == N) {
    if (st == S)
      return 1;
    else
      return 0;
  }
  int ans = 0;
  for (int i = 0; i < N - depth; ++i) {
    int n = arr[i];
    swap(arr[i], arr[N - depth - 1]);
    ans += dfs(st + n * (depth + 1), depth + 1, N, S, arr);
    swap(arr[i], arr[N - depth - 1]);
  }
  return ans;
}

int main() {
  int N, S;
  while (cin >> N >> S) {
    int pats[10];
    for (int i = 0; i < 10; ++i)
      pats[i] = i < N ? 1 : 0;
    reverse(pats, pats + 10);

    int ans = 0;
    do {
      int list[N], *pt = list;
      for (int i = 0; i < 10; ++i)
        if (pats[i])
          *pt++ = i;

      ans += dfs(0, 0, N, S, list);
    } while (next_permutation(pats, pats + 10));
    cout << ans << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
int n, s;
long long int dp[1 << 11][10][250];

long long int check(int bit, int now, int sum) {
  // cout<<bit<<" "<<now<<" "<<sum<<endl;
  if (s == sum && n == now) {
    //   cout<<bit<<" "<<now<<" "<<sum<<endl;
    return 1;
  }
  if (n < now)
    return 0;
  if (s <= sum) {
    if ((bit & 1) == 0)
      return check(bit | 1, now + 1, sum);
    else
      return 0;
  }
  if (dp[bit][now][sum] != -1)
    return dp[bit][now][sum];
  long long int ans = 0;
  for (int i = 0; i < 10; i++) {
    if ((bit & (1 << i)) == 0)
      ans += check(bit | (1 << i), now + 1, sum + (i * (now + 1)));
  }
  dp[bit][now][sum] = ans;
  return ans;
}

int main() {

  //  cout<<(1<<1 | 1<<2)<<endl;
  for (; cin >> n >> s;) {
    memset(dp, -1, sizeof(dp));
    cout << check(0, 0, 0) << endl;
  }
}

Error: MLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int n, s;
long long int dp[1 << 10][10][1000];
long long int check(int bit, int now, int sum) {
  // cout<<bit<<" "<<now<<" "<<sum<<endl;
  if (s == sum && n == now)
    return 1;
  if (sum >= s || n <= now)
    return 0;
  if (dp[bit][now][sum] != -1)
    return dp[bit][now][sum];
  long long int ans = 0;
  for (int i = 0; i < 10; i++) {
    if (!(bit && 1 << i))
      ans += check(bit && 1 << i, now + 1, sum + (i * (now + 1)));
  }
  dp[bit][now][sum] = ans;
  return ans;
}

int main() {

  for (; cin >> n >> s;) {
    memset(dp, -1, sizeof(dp));
    cout << check(0, 0, 0) << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
int ans[10][331] = {0};
int tmp;
int n, s;
int f[10];
int main(void) {
  f[0] = 1;
  f[1] = 1;
  FOR(i, 2, 10) { f[i] = f[i - 1] * i; }
  int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  do {
    tmp = 0;
    REP(i, 10) {
      tmp += (i + 1) * a[i];
      ans[i][tmp]++;
    }
  } while (next_permutation(a, a + 10));
  while (cin >> n >> s) {
    if (s > 330)
      cout << 0 << endl;
    else
      cout << ans[n - 1][s] / f[10 - n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
int n, s;
int memo[10][350];
int dfs(int i, int sum, bool k[10]) {
  if (i == n) {
    if (sum == s)
      return 1;
    else
      return 0;
  }
  if (sum > s)
    return 0;
  int ret = 0;
  REP(j, 10) if ((!k[j]) && (sum + (i + 1) * j <= s)) {
    bool k2[10];
    REP(h, 10) k2[h] = k[h];
    k2[j] = true;
    ret += dfs(i + 1, sum + (i + 1) * j, k2);
  }
  return ret;
}
int dp[11][250][11];
int main(void) {
  while (cin >> n >> s) {
    bool k[10];
    memset(k, 0, sizeof(k));
    memset(memo, -1, sizeof(memo));
    cout << dfs(0, 0, k) << endl;
    /*
    memset(dp,0,sizeof(dp));
    for(int i=0; i<10; i++){
      for(int j=0; j<=10; j++){
        dp[1][i][j] = (i==j)?0:1;
      }
    }
    for(int i=2; i<=n; i++){
      for(int j=0; j<=s; j++){
        for(int k=0; j-i*k>=0&&k<10; k++){
          for(int l=0; l<=10; l++){
            dp[i][j][l] += (k==l)?0:dp[i-1][j-i*k][k];
          }
        }
      }
    }
    cout<<dp[n][s][10]<<endl;
    */
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

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

map<int, int> dp[11][1024];

int main() {
  int n, s;
  while (cin >> n >> s) {
    for (int i = 0; i < 11; ++i) {
      for (int j = 0; j < 1024; ++j) {
        dp[i][j].clear();
      }
    }
    dp[0][0][0] = 1;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 1024; ++j) {
        if (dp[i][j].empty())
          continue;
        for (auto it = dp[i][j].begin(); it != dp[i][j].end(); ++it) {
          for (int k = 0; k <= 9; ++k) {
            if ((j & (1 << k)) == 0) {
              dp[i + 1][j | (1 << k)][it->first + (i + 1) * k] += it->second;
            }
          }
        }
      }
    }
    int res = 0;
    for (int i = 0; i < 1024; ++i) {
      res += dp[n][i][s];
    }
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

bool used[10];

int rec(int k, int ts, int n, int s) {
  if (n < k)
    return (ts == s ? 1 : 0);
  if (s < ts)
    return 0;
  int ret = 0;
  for (int i = 9; i >= 0; --i) {
    if (!used[i]) {
      used[i] = true;
      ret += rec(k + 1, ts + k * i, n, s);
      used[i] = false;
    }
  }
  return ret;
}

int main() {
  int n, s;
  while (cin >> n >> s) {
    memset(used, false, sizeof used);
    cout << rec(1, 0, n, s) << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

map<int, int> dp[11][1024];
int res[11][550];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  dp[0][0][0] = 1;
  memset(res, 0, sizeof res);
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 1024; ++j) {
      for (auto it = dp[i][j].begin(); it != dp[i][j].end(); ++it) {
        for (int k = 0; k <= 9; ++k) {
          if ((j & (1 << k)) == 0) {
            dp[i + 1][j | (1 << k)][it->first + (i + 1) * k] += it->second;
            res[i + 1][it->first + (i + 1) * k] += it->second;
          }
        }
      }
    }
  }
  int n, s;
  while (cin >> n >> s) {
    cout << res[n][s] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

map<int, int> dp[11][1024];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int res[11][550] = {};
  dp[0][0][0] = 1;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 1024; ++j) {
      for (auto it = dp[i][j].begin(); it != dp[i][j].end(); ++it) {
        for (int k = 0; k <= 9; ++k) {
          if ((j & (1 << k)) == 0) {
            dp[i + 1][j | (1 << k)][it->first + (i + 1) * k] += it->second;
            res[i + 1][it->first + (i + 1) * k] += it->second;
          }
        }
      }
    }
  }
  int n, s;
  while (cin >> n >> s) {
    cout << res[n][s] << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int dpset(int n, int data, int sum);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (m > 330 || n > 10) {
      cout << "0" << endl;
    } else {
      cout << dpset(n, 0, m) << endl;
    }
  }
  return 0;
}
int dpset(int n, int data, int sum) {
  int ans = 0;
  if (dp[n][data][sum] >= 0) {
    return dp[n][data][sum];
  }
  if (sum < 0) {
    return 0;
  }
  if (n == 1) {
    if (sum < 10 && !(data & (1 << sum))) {
      ans = 1;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(data & (1 << i))) {
        ans += dpset(n - 1, data | (1 << i), sum - i * n);
      }
    }
  }
  dp[n][data][sum] = ans;
  return ans;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, s;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> s) {
    if (n > 10 || 330 < s) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, s) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1 && s < 10) {
    if (!(x & (1 << s))) {
      y = 1;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1) {
    if (s < 10 && !(x & (1 << s))) {
      y = 1;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1 && s < 10) {
    if (!(x & (1 << s))) {
      y = 1;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1) {
    if (s < 10) {
      if (!(x & (1 << s))) {
        y = 1;
      }
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1 && s < 10) {
    if (!(x & (1 << s))) {
      y = 1;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}