alexjercan/bugnet huggingface dataset:
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: WA

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 (s < 10) {
    if (n == 1) {
      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 "bits/stdc++.h"

using namespace std;

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

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999

int main() {
  int n, s;
  static int dp[11][350][1 << 10] = {};
  dp[0][0][(1 << 10) - 1] = 1;

  for (int i = 1; i <= 10; i++) {
    for (int j = 0; j <= 340; j++) {
      rep(k, 10) {
        for (int l = (1 << 10) - 1; l >= 0; l--) {
          if (j - (k * i) >= 0 && (l & (1 << k)) != 0) {
            dp[i][j][(l ^ (1 << k))] += dp[i - 1][j - (k * i)][l];
          }
        }
      }
    }
  }

  while (cin >> n >> s) {
    int ans = 0;
    if (s <= 340) {
      rep(i, 1 << 10) { ans += dp[n][s][i]; }
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

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

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999
//
// int main(){
//    int n,s;
//    while(cin>>n>>s){
//        if(n==0&&s==0)break;
//
//        int dp[101][2000]={};
//        dp[0][0]=1;
//
//        for(int i=0;i<=100;i++){
//            rep(j,101){
//                rep(k,1001){
//                    if(k-i>=0)
//                        dp[j][k]+=dp[j-1][k-i];
//                }
//            }
//        }
//        cout<<dp[n][s]<<endl;
//    }
//}
//
//

int main() {
  int n, s;
  while (cin >> n >> s) {
    static int dp[11][410][1 << 10] = {};
    dp[0][0][(1 << 10) - 1] = 1;

    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= s; j++) {
        rep(k, 10) {
          for (int l = (1 << 10) - 1; l >= 0; l--) {
            if (j - (k * i) >= 0 && (l & (1 << k)) != 0) {
              dp[i][j][(l ^ (1 << k))] += dp[i - 1][j - (k * i)][l];
            }
          }
        }
      }
    }

    int ans = 0;
    rep(i, 1 << 10) { ans += dp[n][s][i]; }
    cout << ans << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int n, s, ret, dp[15][1010];

signed main(void) {
  VI data;
  REP(i, 10) data.PB(i);
  do {
    int tmp = 0;
    REP(i, 10) {
      tmp += data[i] * (i + 1);
      dp[i][tmp]++;
    }
  } while (next_permutation(ALL(data)));

  int fact[15] = {0};
  fact[0] = 1;
  FOR(i, 1, 10) fact[i] = fact[i - 1] * i;

  while (cin >> n >> s) {
    if (s > 1000) {
      cout << 0 << endl;
      continue;
    }
    cout << dp[n - 1][s] / fact[10 - n] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int n, s, ret, dp[15][1010];

signed main(void) {
  VI data;
  REP(i, 10) data.PB(i);
  do {
    int tmp = 0;
    REP(i, 10) {
      tmp += data[i] * (i + 1);
      dp[i][tmp]++;
    }
  } while (next_permutation(ALL(data)));

  int fact[10] = {0};
  fact[0] = 1;
  FOR(i, 1, 10) fact[i] = fact[i - 1] * i;

  while (cin >> n >> s) {
    cout << dp[n - 1][s] / fact[10 - n] << endl;
  }

  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rep(i, n) range(i, 0, n)
using namespace std;

int n, s;
int memo[11][1010];

void rec(int index, int sum, int mask) {
  memo[index][sum]++;
  if (index == 10)
    return;
  rep(i, 10) {
    if (mask & (1 << i))
      continue;
    int nmask = mask | (1 << i);
    int nsum = sum + (index + 1) * i;
    rec(index + 1, nsum, nmask);
  }
}

int main(void) {
  rec(0, 0, 0);
  while (cin >> n >> s) {
    if (cin.eof())
      break;
    if (s < 1010)
      cout << memo[n][s] << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define rep(i, n) range(i, 0, n)
using namespace std;

int n, s;
int memo[11][1010];

void rec(int index, int sum, int mask) {
  memo[index][sum]++;
  if (index == 10)
    return;
  rep(i, 10) {
    if (mask & (1 << i))
      continue;
    int nmask = mask | (1 << i);
    int nsum = sum + (index + 1) * i;
    rec(index + 1, nsum, nmask);
  }
}

int main(void) {
  rec(0, 0, 0);
  while (cin >> n >> s) {
    if (cin.eof())
      break;
    cout << memo[n][s] << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A) (A).begin(), (A).end()
#define DUMP(A) cout << #A << "=" << (A) << endl
#define SIZE(A) (int)((A).size())
using namespace std;
typedef long long ll;

int ret;
bool used[10];
int S;
int dat[11][1000];
void solve(int nsum, int at) {
  if (at == 11)
    return;
  else {
    if (nsum < 1000)
      dat[at][nsum]++;
    for (int i = 0; i < 10; i++) {
      if (!used[i]) {
        used[i] = true;
        solve(nsum + i * (at + 1), at + 1);
        used[i] = false;
      }
    }
  }
}

int main() {
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 1000; j++) {
      dat[i][j] = 0;
    }
  }
  solve(0, 0);
  int N, S;
  while (scanf("%d%d", &N, &S) != -1) {
    if (S >= 1000)
      printf("0\\n");
    else
      printf("%d\\n", dat[N][S]);
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A) (A).begin(), (A).end()
#define DUMP(A) cout << #A << "=" << (A) << endl
#define SIZE(A) (int)((A).size())
using namespace std;
typedef long long ll;

int ret;
bool used[10];
int S;
int dat[10][1000];
void solve(int nsum, int at) {
  if (at == 10)
    return;
  else {
    if (nsum < 1000)
      dat[at][nsum]++;
    for (int i = 0; i < 10; i++) {
      if (!used[i]) {
        used[i] = true;
        solve(nsum + i * (at + 1), at + 1);
        used[i] = false;
      }
    }
  }
}

int main() {
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 1000; j++) {
      dat[i][j] = 0;
    }
  }
  solve(0, 0);
  int N, S;
  while (scanf("%d%d", &N, &S) != -1) {
    if (S >= 1000)
      printf("0\\n");
    else
      printf("%d\\n", dat[N][S]);
  }
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

using namespace std;

const int N = 10 + 1;
const int S = 330 + 1; // 作れる値の最大値+1
int dp[N][S][1 << N];  // 残り個数, 作る値, 今迄どれを使ったか

int solve(int n, int s, int used) {
  // cout << n << ' ' << s << ' ' << used << endl;
  if (s < 0)
    return 0;
  if (n == 0) {
    if (s == 0)
      return 1;
    return 0;
  }
  if (dp[n][s][used] != -1)
    return dp[n][s][used];
  int cnt = 0;
  for (int i = 0; i <= 9; i++) {
    if (used & (1 << i))
      continue;
    // cout << "used " << i << endl;
    cnt += solve(n - 1, s - i * n, used | (1 << i));
  }
  return dp[n][s][used] = cnt;
}

void init() { memset(dp, -1, sizeof(dp)); }

int main() {
  int n, s;
  init();
  while (cin >> n >> s) {
    if (s >= S) {
      cout << 0 << endl;
      continue;
    }
    cout << solve(n, s, 0) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

const int N = 10;
const int S = 330 + 1;
int dp[S][N][1 << N];

int solve(int n, int s, int used) {
  // cout << n << ' ' << s << ' ' << used << endl;
  if (s < 0)
    return 0;
  if (n == 0) {
    if (s == 0)
      return 1;
    return 0;
  }
  if (dp[n][s][used] != -1)
    return dp[n][s][used];
  int cnt = 0;
  for (int i = 0; i <= 9; i++) {
    if (used & (1 << i))
      continue;
    // cout << "used " << i << endl;
    cnt += solve(n - 1, s - i * n, used | (1 << i));
  }
  return dp[n][s][used] = cnt;
}

void init() {
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i <= 9; i++)
    dp[1][i][1 << i] = 1;
}

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


#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n, s;
  int c[11][900];
  int p[10];
  for (int j = 0; j < 11; j++)
    for (int i = 0; i < 900; i++)
      c[j][i] = 0;
  for (int n = 0; n < 11; n++) {
    for (int i = 0; i < 10; i++)
      p[i] = i;
    do {
      sort(p + n, p + 10);
      reverse(p + n, p + 10);
      s = 0;
      for (int i = 0; i < n; i++)
        s += p[i] * (i + 1);
      c[n][s]++;
    } while (next_permutation(p, p + 10));
  }

  while (cin >> n >> s) {
    if (s < 900)
      cout << c[n][s] << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n, s, ss;
  while (cin >> n >> s) {
    int p[10];
    for (int i = 0; i < 10; i++)
      p[i] = i;
    int count = 0;
    do {
      sort(p + n, p + 10);
      reverse(p + n, p + 10);
      ss = 0;
      for (int i = 0; i < n; i++)
        ss += p[i] * (i + 1);
      if (ss == s)
        count++;
    } while (next_permutation(p, p + 10));
    cout << count << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;

#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define DEB 0

int dp[1 << 10][331];

int main() {
  int n, s;
  while (~scanf("%d%d", &n, &s)) {
    rep(i, 1 << 10) rep(j, 331) dp[i][j] = 0;
    if (s > 330) {
      puts("0");
      continue;
    }

    rep(i, n) {
      if (i == 0) {
        rep(k, 10) { dp[1 << k][k] = 1; }
      } else {
        int comb = (1 << i) - 1;
        while (comb < 1 << 10) {
          rep(j, s + 1) if (dp[comb][j]) {
            rep(k, 10) if (!(comb & (1 << k))) {
              if (j + (i + 1) * k <= s) {
                dp[comb | (1 << k)][j + (i + 1) * k] += dp[comb][j];
              }
#if DEB
              printf("__comb:%d|(1<<%d)][%d]\\n", comb, k, j + (i + 1) * k);
#endif
            }
          }
          int x = comb & -comb;
          int y = comb + x;
          comb = ((comb & ~y) / x >> 1) | y;
#if DEB
          printf("comb:%d i:%d\\n", comb, i + 1);
#endif
        }
      }
    }
    int ans = 0;
    int comb = (1 << n) - 1;
    while (comb < 1 << 10) {
      ans += dp[comb][s];
      int x = comb & -comb;
      int y = comb + x;
      comb = ((comb & ~y) / x >> 1) | y;
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define DEB 0

int dp[1 << 10][256];

int main() {
  int n, s;
  while (~scanf("%d%d", &n, &s)) {
    rep(i, 1 << 10) rep(j, 256) dp[i][j] = 0;

    rep(i, n) {
      if (i == 0) {
        rep(k, 10) { dp[1 << k][k] = 1; }
      } else {
        int comb = (1 << i) - 1;
        while (comb < 1 << 10) {
          rep(j, s + 1) if (dp[comb][j]) {
            rep(k, 10) if (!(comb & (1 << k))) {
              if (j + (i + 1) * k <= s) {
                dp[comb | (1 << k)][j + (i + 1) * k] += dp[comb][j];
              }
#if DEB
              printf("__comb:%d|(1<<%d)][%d]\\n", comb, k, j + (i + 1) * k);
#endif
            }
          }
          int x = comb & -comb;
          int y = comb + x;
          comb = ((comb & ~y) / x >> 1) | y;
#if DEB
          printf("comb:%d i:%d\\n", comb, i + 1);
#endif
        }
      }
    }
    int ans = 0;
    int comb = (1 << n) - 1;
    while (comb < 1 << 10) {
      ans += dp[comb][s];
      int x = comb & -comb;
      int y = comb + x;
      comb = ((comb & ~y) / x >> 1) | y;
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long
#define for0(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int n, s;
int sum = 0;
bool b[20];
int f(int k) {
  if (sum + 9 * k * (k + 1) / 2 < s)
    return 0;
  int r = 0;
  if (k == 0)
    return s == sum;
  for0(i, 10) {
    if (sum + i * k > s)
      break;
    if (b[i])
      continue;
    b[i] = 1;
    sum += k * i;
    r += f(k - 1);
    b[i] = 0;
    sum -= k * i;
  }
  return r;
}
signed main() {
  while (cin >> n >> s)
    printf("%d\\n", f(n));
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define int long long
using namespace std;
int n, s;
int a[20];
bool b[20];
int f(int p) {
  if (p > n) {
    int r = 0;
    for (int i = 1; i <= n; i++)
      r += a[i] * i;
    return r == s;
  }
  int r = 0;
  for (int i = 0; i < 10; i++) {
    if (!b[i]) {
      a[p] = i;
      b[i] = 1;
      r += f(p + 1);
      a[p] = -1;
      b[i] = 0;
    }
  }
  return r;
}
signed main() {
  while (cin >> n >> s)
    cout << f(1) << endl;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)

const int MAXN = 10;

int ncase;
bool used[MAXN];
int mins[MAXN + 1];
int maxs[MAXN + 1];

void sum(int n, int m, int s, int t) {
  if (m == n) {
    if (s == t)
      ncase += 1;
    return;
  }
  if (t > s)
    return;
  if (m == n - 1 && (s - t) % (m + 1) != 0)
    return;
  if (used[0] && (s - t) < (m + 1))
    return;
  if (s - t < mins[n - m] || maxs[n - m] < s - t)
    return;
  REP(i, MAXN) {
    if (!used[i]) {
      used[i] = true;
      sum(n, m + 1, s, t + i * (m + 1));
      used[i] = false;
    }
  }
}

int minsum(int n) {
  int s = 0;
  REP(i, n) s += i * (n - i);
  return s;
}

int maxsum(int n) {
  int s = 0;
  REP(i, n) s += (MAXN - 1 - i) * (MAXN - i);
  return s;
}

void solve(int n, int s) {
  ncase = 0;
  REP(i, MAXN) used[i] = false;
  sum(n, 0, s, 0);
  cout << ncase << endl;
}
int main(void) {
  REP(i, MAXN) {
    mins[i + 1] = minsum(i + 1);
    maxs[i + 1] = maxsum(i + 1);
  }
  int n, s;
  while ((cin >> n >> s)) {
    solve(n, s);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)

const int MAXN = 10;

int ncase;
bool used[MAXN];

void sum(int n, int m, int s, int t) {
  if (m == n) {
    if (s == t)
      ncase += 1;
    return;
  }
  if (t > s)
    return;
  if (m == n - 1 && (s - t) % (m + 1) != 0)
    return;
  if (used[0] && (s - t) < (m + 1))
    return;
  REP(i, MAXN) {
    if (!used[i]) {
      used[i] = true;
      sum(n, m + 1, s, t + i * (m + 1));
      used[i] = false;
    }
  }
}

int minsum(int n) {
  int s = 0;
  REP(i, n) s += i * (n - i);
  return s;
}

int maxsum(int n) {
  int s = 0;
  REP(i, n) s += (MAXN - 1 - i) * (MAXN - i);
  return s;
}

void solve(int n, int s) {
  if (s < minsum(n) || maxsum(n) < s) {
    cout << 0 << endl;
    return;
  }
  ncase = 0;
  REP(i, MAXN) used[i] = false;
  sum(n, 0, s, 0);
  cout << ncase << endl;
}
int main(void) {
  int n, s;
  while ((cin >> n >> s)) {
    solve(n, s);
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
int memo[11][1 << 10][335];

int solve(int n, int f, int s) {
  if (s > 330)
    return 0;
  if (s < 335 && memo[n][f][s] != -1) {
    return memo[n][f][s];
  }

  if (n == 0) {
    if (s == 0) {
      memo[n][f][s] = 1;
      return 1;
    } else {
      memo[n][f][s] = 0;
      return 0;
    }
  }
  if (s < 0)
    return 0;

  int ans = 0;
  for (int i = 0; i < 10; i++) {
    if (((f >> i) & 1) && (s - n * i > -1)) {
      ans += solve(n - 1, f - (1 << i), s - n * i);
    }
  }
  memo[n][f][s] = ans;
  return ans;
}

int main() {

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

Error: MLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int memo[11][1 << 10][900];

int solve(int n, int f, int s) {
  if (s < 900 && memo[n][f][s] != -1) {
    return memo[n][f][s];
  }
  if (n == 0) {
    if (s == 0)
      return 1;
    else
      return 0;
  }
  if (s < 0)
    return 0;

  int ans = 0;
  for (int i = 0; i < 10; i++) {
    if ((f >> i) & 1) {
      ans += solve(n - 1, f - (1 << i), s - n * i);
    }
  }
  memo[n][f][s] = ans;
  return ans;
}

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

#include <algorithm>
#include <iostream>
using namespace std;

int N, S;
int dp[1 << 10][500];

int main() {
  while (cin >> N >> S) {
    if (N > 10 || S >= 500) {
      cout << 0 << endl;
      continue;
    }

    fill(dp[0], dp[1 << 10], 0);
    dp[0][0] = 1;
    for (int i = 0; i < (1 << 10); ++i) {
      int t = __builtin_popcount(i) + 1;
      if (t > N)
        continue;
      for (int j = 0; j <= S; ++j) {
        if (dp[i][j] == 0)
          continue;
        for (int k = 0; k < 10; ++k) {
          if (i & (1 << k))
            continue;
          int ni = (i | (1 << k));
          int nj = j + k * t;
          if (nj > S)
            continue;
          dp[ni][nj] += dp[i][j];
        }
      }
    }
    int res = 0;
    for (int i = 0; i < (1 << 10); ++i) {
      if (__builtin_popcount(i) == N) {
        res += dp[i][S];
      }
    }
    cout << res << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int N, S;
bool used[10];

int rec(int k, int r) {
  if (N > 10)
    return 0;
  if (k == N)
    return r == S;
  if (r > S)
    return 0;

  int res = 0;
  for (int i = 0; i < 10; ++i) {
    if (!used[i]) {
      used[i] = true;
      res += rec(k + 1, r + (k + 1) * i);
      used[i] = false;
    }
  }
  return res;
}

int main() {
  while (cin >> N >> S) {
    fill(used, used + 10, false);
    cout << rec(0, 0) << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int n, s;
vector<vector<vector<int>>> dp;
int DP(int nn, int ss, int k) {
  // cout<<nn<<" "<<ss<<" "<<k<<endl;
  if (nn == 0)
    return ss == 0;
  if (ss < 0 || s < ss || n > 10)
    return 0;
  if (dp[nn][ss][k] != -1)
    return dp[nn][ss][k];
  dp[nn][ss][k]++;
  for (int i = 0; i < 10; i++) {
    if (!(k & (1 << i)))
      dp[nn][ss][k] += DP(nn - 1, ss - nn * i, k + (1 << i));
  }
  return dp[nn][ss][k];
}

int solve() { return DP(n, s, 0); }

int main() {
  dp.resize(11);
  for (int i = 0; i < dp.size(); i++) {
    dp[i].resize(1 * 1 + 2 * 2 + 3 * 3 + 4 * 4 + 5 * 5 + 6 * 6 + 7 * 7 + 8 * 8 +
                 9 * 9 + 100);
    for (int j = 0; j < dp[i].size(); j++) {
      dp[i][j].resize(1 << 10);
      for (int k = 0; k < dp[i][j].size(); k++) {
        dp[i][j][k] = -1;
      }
    }
  }
  while (cin >> n >> s) {
    if (s < dp[0].size()) {
      cout << solve() << endl;
    } else {
      cout << 0 << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int n, s;
const int MAX =
    1 * 1 + 2 * 2 + 3 * 3 + 4 * 4 + 5 * 5 + 6 * 6 + 7 * 7 + 8 * 8 + 9 * 9 + 100;
const int LIST = 1 << 10;
int dp[12][MAX][LIST];
int DP(int nn, int ss, int k) {
  // cout<<nn<<" "<<ss<<" "<<k<<endl;
  if (nn == 0)
    return ss == 0;
  if (ss < 0 || s < ss || n > 10)
    return 0;
  if (dp[nn][ss][k] != 0)
    return dp[nn][ss][k];
  for (int i = 0; i < 10; i++) {
    if (!(k & (1 << i)))
      dp[nn][ss][k] += DP(nn - 1, ss - nn * i, k + (1 << i));
  }
  return dp[nn][ss][k];
}

int solve() { return DP(n, s, 0); }

int main() {
  while (cin >> n >> s) {
    if (s < MAX) {
      cout << solve() << endl;
    } else {
      cout << 0 << endl;
    }
  }
}