alexjercan/bugnet huggingface dataset:
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define MP make_pair
#define all(s) (s).begin(), (s).end()
#define rev(s) (s).rbegin(), (s).rend()
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

int memo[1 << 10][10][1000];

int dfs(int used, int n, int s) {
  if (n == 0)
    return s == 0;
  if (memo[used][n][s] != -1)
    return memo[used][n][s];

  int cnt = 0;
  rep(i, 10) {
    int num = 1 << i;
    if (used & num)
      continue;
    used |= num;
    cnt += dfs(used, n - 1, s - i * n);
    used &= ~num;
  }
  return memo[used][n][s] = cnt;
}

int main() {
  memset(memo, -1, sizeof(memo));
  int n, s;
  while (cin >> n >> s) {
    if (s > 1000)
      cout << 0 << endl;
    else
      cout << dfs(0, n, s) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

bool used[10];

int solve(int n, int s, int k = 0, int sum = 0) {
  if (n == k && s == sum) {
    return 1;
  }
  if (n < k || s < sum) {
    return 0;
  }

  int count = 0;

  for (int i = 0; i < 10; i++) {
    if (used[i] != true) {
      used[i] = true;
      count += solve(n, s, k + 1, sum + i * (k + 1));
      used[i] = false;
    }
  }

  return count;
}

int main() {
  int n, s;

  while (cin >> n >> s) {
    cout << solve(n, s) << endl;
  }

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

#include <stdio.h>
#include <string.h>

void rec(char *num, int k, int sum);

int s, n;
int dp[12][331];

int main(void) {
  char num[10];

  for (int i = 0; i < 10; i++) {
    num[i] = 1;
  }

  for (int i = 0; i < 12; i++) {
    for (int j = 0; j < 331; j++) {
      dp[i][j] = 0;
    }
  }

  for (int i = 0; i < 10; i++) {
    char temp[10];
    memcpy(temp, num, 10);
    temp[i] = 0;
    rec(temp, 2, i);
  }

  while (scanf("%d %d", &n, &s) != EOF) {
    if (s > 330) {
      printf("0\\n");
      continue;
    } else if (n == 10 && s >= 248) {
      s = 165 + (330 - s);
    } else if (n == 9 && s >= 203) {
      s = 120 + (285 - s);
    }

    printf("%d\\n", dp[n][s]);
  }

  return 0;
}

void rec(char *num, int k, int sum) {
  if (sum < 248)
    dp[k - 1][sum]++;

  for (int i = 0; i < 10; i++) {
    if (num[i] != 0) {
      char temp[10];
      memcpy(temp, num, 10);
      temp[i] = 0;

      sum += (i * k);
      if (sum >= 248)
        continue;

      rec(temp, k + 1, sum);
      sum -= (i * k);
    }
  }
  return;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>

void rec(char *num, int k, int sum);

int s, n;
int ans;
int dp[11][331];

int main(void) {
  char num[10];

  while (scanf("%d %d", &n, &s) != EOF) {
    ans = 0;
    for (int i = 0; i < 10; i++) {
      num[i] = 1;
    }

    for (int i = 0; i < 11; i++) {
      for (int j = 0; j < 331; j++) {
        dp[i][j] = -1;
      }
    }

    if (s > 330) {
      printf("0\\n");
      continue;
    } else if (n == 10 && s >= 248) {
      s = 165 + (330 - s);
    } else if (n == 9 && s >= 203) {
      s = 120 + (285 - s);
    } else if (n == 8 && s >= 163) {
      s = 84 + (240 - s);
    }

    if (dp[n][s] != -1) {
      printf("%d\\n", dp[n][s]);
      continue;
    }

    for (int i = 0; i < 10; i++) {
      char temp[10];
      memcpy(temp, num, 10);
      temp[i] = 0;
      rec(temp, 2, i);
    }

    dp[n][s] = ans;
    printf("%d\\n", ans);
  }

  return 0;
}

void rec(char *num, int k, int sum) {
  if (k == n + 1) {
    if (sum == s) {
      ans++;
    }
    return;
  }

  for (int i = 0; i < 10; i++) {
    if (num[i] != 0) {
      char temp[10];
      sum += (i * k);

      if (sum > s)
        continue;
      memcpy(temp, num, 10);
      temp[i] = 0;
      rec(temp, k + 1, sum);
      sum -= (i * k);
    }
  }
  return;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int ans, n, s;
int memo[1050][1000][10];
int rec(int bit, int x, int d) {
  int res = 0;
  if (memo[bit][x][d] != -1)
    return memo[bit][x][d];
  if (d == n) {
    if (x == s)
      return 1;
    return 0;
  }
  if (x > s)
    return 0;
  for (int i = 0; i < 10; i++) {
    if (bit >> i & 1)
      continue;
    res += rec(bit + (1 << i), x + i * (d + 1), d + 1);
  }
  return memo[bit][x][d] = res;
  ;
}
int main() {
  while (cin >> n >> s) {
    fill(memo[0][0], memo[1049][999], -1);
    cout << rec(0, 0, 0) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int ans, n, s;
void rec(int bit, int x, int d) {
  if (d == n) {
    if (x == s)
      ans++;
    return;
  }
  if (x > s)
    return;
  for (int i = 0; i < 10; i++) {
    if (bit >> i & 1)
      continue;
    rec(bit + (1 << i), x + i * (d + 1), d + 1);
  }
}
int main() {
  while (cin >> n >> s) {
    ans = 0;
    rec(0, 0, 0);
    cout << ans << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
unsigned short dp[11][1024][341], ans[11][341];
int main() {
  unsigned short i, j, k, s;
  dp[0][0][0] = 1;
  for (i = 0; i < 10; i++)
    for (j = 0; j < 1024; j++)
      for (k = 0; k < 331; k++) {
        if (!dp[i][j][k])
          continue;
        for (s = 0; s < 10; s++)
          if (!(j & (1 << s)))
            dp[i + 1][j | (1 << s)][i * s + s + k] += dp[i][j][k];
      }
  for (i = 0; i < 11; i++)
    for (j = 0; j < 1024; j++)
      for (k = 0; k < 331; ans[i][k] += dp[i][j][k], k++)
        ;
  while (scanf("%hu %hu", &i, &j) != EOF) {
    if (i > 10 || j > 330) {
      puts("0");
      continue;
    } else
      printf("%hu\\n", ans[i][j]);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int cnt;
void dfs(int left, int mask, int sum) {
  if (sum < 0)
    return;
  else if (!sum) {
    if (!left || (left == 1 && !(mask & 1)))
      cnt++;
    return;
  }
  if (left <= 0)
    return;
  for (int i = 0; i < 10; i++)
    if (!(mask & (1 << i))) {
      if (sum - left * i < 0)
        return;
      else
        dfs(left - 1, mask | (1 << i), sum - left * i);
    }
}
int main() {
  int i, N, s;
  while (scanf("%d %d", &N, &s) != EOF) {
    if (N > 10) {
      puts("0");
      continue;
    }
    cnt = 0;
    for (i = 0; i < 10; i++)
      dfs(N - 1, 1 << i, s - N * i);
    printf("%d\\n", cnt);
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

int dp[10 + 1][10000];
int memo[10];

void rec(int size, int depth, int sum) {
  if (size + 1 == depth) {
    dp[size][sum]++;
  } else {
    for (int i = 0; i <= 9; i++) {
      if (memo[i] == 0) {
        memo[i] = 1;
        rec(size, depth + 1, sum + i * depth);
        memo[i] = 0;
      }
    }
  }
}

int main() {
  memset(dp, 0, sizeof(dp));

  for (int i = 1; i <= 10; i++) {
    memset(memo, 0, sizeof(memo));
    rec(i, 1, 0);
  }

  int n, s;
  while (cin >> n >> s) {
    cout << dp[n][s] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

int n, s, ans;

void rec(int depth, int sum, int used) {
  if (sum > s)
    return;
  if (depth == n) {
    if (s == sum)
      ans++;
    return;
  }
  depth++;
  for (int i = 0; i < 10; i++)
    if ((used & (0x01 << i)) == 0)
      rec(depth, sum + depth * i, used | (0x01 << i));
}

int main() {
  while (cin >> n >> s) {
    ans = 0;
    for (int i = 0; i < 10; i++)
      rec(1, i, (0x01 << i));
    cout << ans << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int n, s;
int dp[350][1024];

int rec(int k, int sum, int u) {
  int res = 0;
  if (k == 0 && sum == 0)
    return 1;
  if (dp[sum][u] >= 0)
    return dp[sum][u];
  if (k == 0)
    return 0;

  for (int i = 0; i < 10; i++) {
    if (u >> i & 1) {
      if (sum - k * i >= 0)
        res += rec(k - 1, sum - k * i, u - (1 << i));
    }
  }
  dp[sum][u] = res;
  return res;
}

int main() {
  for (int i = 0; i < 350; i++) {
    for (int j = 0; j < 1024; j++)
      dp[i][j] = -1;
  }
  while (cin >> n >> s) {
    if (s > 330)
      cout << 0 << endl;
    else {
      for (int i = 0; i < 350; i++) {
        for (int j = 0; j < 1024; j++)
          dp[i][j] = -1;
      }
      cout << rec(n, s, 1023) << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int n, s;
int dp[350][1024];

int rec(int k, int sum, int u) {
  int res = 0;
  if (k == 0 && sum == 0)
    return 1;
  if (dp[sum][u] >= 0)
    return dp[sum][u];
  if (k == 0)
    return dp[sum][u] = 0;

  for (int i = 0; i < 10; i++) {
    if (u >> i & 1) {
      if (sum - k * i >= 0)
        res += rec(k - 1, sum - k * i, u - (1 << i));
    }
  }
  dp[sum][u] = res;
  return res;
}

int main() {
  for (int i = 0; i < 350; i++) {
    for (int j = 0; j < 1024; j++)
      dp[i][j] = -1;
  }
  dp[0][0] = 1;
  while (cin >> n >> s)
    cout << rec(n, s, 1023) << endl;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int n, s, res[10][330] = {0};
bool num[10] = {0};
void combinations(int c, int sum) {
  if (c == 11)
    return;
  for (int i = 0; i < 10; i++) {
    if (num[i])
      continue;
    num[i] = 1;
    ++res[c + 1][sum + i * (c + 1)];
    combinations(c + 1, sum + i * (c + 1));
    num[i] = 0;
  }
}

int main() {
  combinations(0, 0);
  while (cin >> n) {
    cin >> s;
    if (n > 10 || s > 330) {
      n = 0;
      s = 0;
    }
    cout << res[n][s] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n, s;
bool num[10] = {0};
int combinations(int c, int sum) {
  if (sum > s)
    return 0;
  if (c == n) {
    if (sum == s)
      return 1;
    return 0;
  }
  int res = 0;
  for (int i = 0; i < 10; i++) {
    if (num[i])
      continue;
    num[i] = 1;
    res += combinations(c + 1, sum + i * (c + 1));
    num[i] = 0;
  }
  return res;
}

int main() {
  while (cin >> n) {
    cin >> s;
    if (n > 10 || s > 330) {
      cout << 0 << endl;
      continue;
    }
    cout << combinations(0, 0) << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#define MAX_N 10
#define MAX_S 10000
using namespace std;

int ans[MAX_N + 1][MAX_S];
int used[10];

void calc(int n, int depth, int sum) {
  if (n + 1 == depth) {
    ans[n][sum]++;
  } else {
    for (int i = 0; i < 10; i++) {
      if (used[i] == 0) {
        used[i] = 1;
        calc(n, depth + 1, i * depth + sum);
        used[i] = 0;
      }
    }
  }
}

int main() {
  int n, s;
  memset(ans, 0, sizeof(ans));
  // calc any answers for n, s in advance.
  for (int i = 0; i < 10; i++) {
    memset(used, 0, sizeof(used));
    calc(i + 1, 1, 0);
  }
  while (cin >> n >> s) {
    cout << ans[n][s] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#define MAX_N 10
#define MAX_S 1000
using namespace std;

int ans[MAX_N + 1][MAX_S];
int used[10];

void calc(int n, int depth, int sum) {
  if (n + 1 == depth) {
    ans[n][sum]++;
    return;
  }
  for (int i = 0; i < 10; i++) {
    if (used[i] == 0) {
      used[i] = 1;
      calc(n, depth + 1, i * depth + sum);
      used[i] = 0;
    }
  }
}

int main() {
  int n, s;
  memset(ans, 0, sizeof(ans));
  // calc any answers for n, s in advance.
  for (int i = 0; i < 10; i++) {
    memset(used, 0, sizeof(used));
    calc(i + 1, 1, 0);
  }
  while (cin >> n >> s) {
    cout << ans[n][s] << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int n, s;
// sum <= 10 * 9 + 9 * 8 + 8 * 7 ...
int memo[10][1 << 10][400];

int dfs(int now, int bit, int sum) {
  if (now >= n)
    return sum == s;
  if (sum > s)
    return 0;
  if (memo[now][bit][sum] != -1)
    return memo[now][bit][sum];

  int ret = 0;
  for (int i = 0; i < 10; ++i) {
    if (!(bit & (1 << i))) {
      ret += dfs(now + 1, bit | (1 << i), sum + i * (now + 1));
    }
  }
  return memo[now][bit][sum] = ret;
}

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

Error: MLE

Fixed submission:

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

int n, s;
int memo[10][1 << 10][10010];

int dfs(int now, int bit, int sum) {
  if (now >= n)
    return sum == s;
  if (memo[now][bit][sum] != -1)
    return memo[now][bit][sum];

  int ret = 0;
  for (int i = 0; i < 10; ++i) {
    if (!(bit & (1 << i))) {
      ret += dfs(now + 1, bit | (1 << i), sum + i * (now + 1));
    }
  }
  return memo[now][bit][sum] = ret;
}

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

#include <cstring>
#include <iostream>

using namespace std;

#define LIMIT 330

int cnt[11][LIMIT + 1];
bool used[11];

void make(int k, int N, int sum) {
  if (sum > LIMIT)
    return;

  if (N == 0) {
    cnt[k][sum]++;
    return;
  }

  for (int i = 0; i <= 9; i++) {
    if (!used[i]) {
      used[i] = true;
      make(k + 1, N - 1, sum + (k + 1) * i);
      used[i] = false;
    }
  }
}

void init() {
  for (int i = 0; i <= 10; i++) {
    memset(used, false, sizeof(used));
    make(0, i, 0);
  }
}

int main() {
  int n, s;

  init();

  while (cin >> n >> s) {
    if (s <= LIMIT) {
      cout << cnt[n][s] << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

#define LIMIT 330

int cnt[11][500];
bool used[11];

void make(int k, int N, int sum) {
  if (sum > LIMIT)
    return;

  if (N == 0) {
    cnt[k][sum]++;
    return;
  }

  for (int i = 0; i <= 9; i++) {
    if (!used[i]) {
      used[i] = true;
      make(k + 1, N - 1, sum + (k + 1) * i);
      used[i] = false;
    }
  }
}

void init() {
  for (int i = 0; i <= 9; i++) {
    make(0, i, 0);
  }
}

int main() {
  int n, s;

  init();

  while (cin >> n >> s) {
    cout << cnt[n][s] << endl;
  }

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

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int n, s, memo[1024][500];

int search(int stat, int sum, int dep) {
  if (dep == n)
    return memo[stat][sum] = (s == sum);
  if (~memo[stat][sum])
    return memo[stat][sum];
  if (sum > s)
    return 0;

  int cnt = 0;
  for (int i = 0; i < 10; i++) {
    if ((stat & (1 << i)) == 0) {
      stat |= 1 << i;
      cnt += search(stat, sum + i * (n - dep), dep + 1);
      stat &= ~(1 << i);
    }
  }
  return memo[stat][sum] = cnt;
}

int main() {
  while (cin >> n >> s) {
    if (n == 0 || s >= 1000) {
      puts("0");
      continue;
    }
    memset(memo, -1, sizeof(memo));
    cout << search(0, 0, 0) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int n, s, memo[1024][500];

int search(int stat, int sum, int dep) {
  if (dep == n)
    return memo[stat][sum] = (s == sum);
  // if(~memo[stat][sum])    return memo[stat][sum];
  if (sum > s)
    return 0;

  int cnt = 0;
  for (int i = 0; i < 10; i++) {
    if ((stat & (1 << i)) == 0) {
      stat |= 1 << i;
      cnt += search(stat, sum + i * (n - dep), dep + 1);
      stat &= ~(1 << i);
    }
  }
  return memo[stat][sum] = cnt;
}

int main() {
  while (cin >> n >> s) {
    if (n == 0 || s >= 1000) {
      puts("0");
      continue;
    }
    memset(memo, -1, sizeof(memo));
    cout << search(0, 0, 0) << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n, s;
int dp[20][500][1100];
int solve(int i, int sum, int used) {
  if (dp[i][sum][used] >= 0)
    return dp[i][sum][used];
  if (i == n + 1 && sum == s)
    return 1;
  if (i > n || sum > s)
    return 0;
  int res = 0;
  REP(j, 10) {
    if (((used >> j) & 1) == 0 && sum + i * j <= s) {
      res += solve(i + 1, sum + i * j, used | (1 << j));
    }
  }
  return dp[i][sum][used] = res;
}

int main() {
  while (cin >> n >> s) {
    MS(dp, -1);
    cout << solve(1, 0, 0) << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n, s;
int dp[20][1000][1100];
int solve(int i, int sum, int used) {
  if (dp[i][sum][used] >= 0)
    return dp[i][sum][used];
  if (i == n + 1 && sum == s)
    return 1;
  if (i > n || sum > s)
    return 0;
  int res = 0;
  REP(j, 10) {
    if (((used >> j) & 1) == 0 && sum + i * j <= s) {
      res += solve(i + 1, sum + i * j, used | (1 << j));
    }
  }
  return dp[i][sum][used] = res;
}

int main() {
  while (cin >> n >> s) {
    MS(dp, -1);
    cout << solve(1, 0, 0) << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n, s;
int memo[11][800][1 << 10];

int solve(int i, int j, int v) {
  if (memo[i][j][v] >= 0)
    return memo[i][j][v];
  if (i == n) {
    if (j == s)
      return 1;
    else
      return 0;
  }

  int res = 0;
  REP(k, 10) {
    if ((v >> k) & 1)
      continue;
    if (j + k * (i + 1) > s)
      break;
    res += solve(i + 1, j + (i + 1) * k, v | (1 << k));
  }
  return memo[i][j][v] = res;
}

int main() {
  while (cin >> n >> s) {
    MS(memo, -1);
    cout << solve(0, 0, 0) << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n, s;
int memo[100][1000][1 << 10];

int solve(int i, int j, int v) {
  if (memo[i][j][v] >= 0)
    return memo[i][j][v];
  if (i == n) {
    if (j == s)
      return 1;
    else
      return 0;
  }

  int res = 0;
  REP(k, 10) {
    if ((v >> k) & 1)
      continue;
    if (j + k * (i + 1) > s)
      break;
    res += solve(i + 1, j + (i + 1) * k, v | (1 << k));
  }
  return memo[i][j][v] = res;
}

int main() {
  while (cin >> n >> s) {
    MS(memo, -1);
    cout << solve(0, 0, 0) << endl;
  }
  return 0;
}