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

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

int main() {
  int n, s;
  int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int mat[10][10001] = {};

  do {
    int tmp = 0;
    for (int i = 0; i < 10; i++) {
      tmp += (i + 1) * a[i];
      mat[i][tmp]++;
    }
  } while (next_permutation(a, a + 10));

  while (cin >> n >> s) {
    int ans = mat[n - 1][s];
    for (int i = 1; i <= 10 - n; i++)
      ans /= i;
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  vector<int> v;
  for (int i = 0; i <= 9; i++)
    v.push_back(i);

  int n, s;
  while (cin >> n >> s) {
    sort(v.begin(), v.end());
    int ans = 0;
    do {
      int tmp = 0;
      for (int i = 0; i < n; i++)
        tmp += (i + 1) * v[i];
      if (tmp == s)
        ans++;
    } while (next_permutation(v.begin(), v.end()));

    for (int i = 1; i <= 10 - n; i++)
      ans /= i;

    cout << ans << endl;
  }

  return 0;
}
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<ll> vl;
typedef complex<double> P;
typedef pair<int, int> pii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = 1; i < n; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \\
  cout << #v << ":";                                                           \\
  REP(i, v.size()) cout << " " << v[i];                                        \\
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define MOD (ll)(1e9 + 7)
#define ADD(a, b) a = ((a) + (b)) % MOD
#define FIX(a) ((a) % MOD + MOD) % MOD

int dp[11][353];

// int dfs(int cnt, int msk, int cur){
//   if(cnt>10 || cur>330) return 0;
//   if(cnt == 0) return (cur==0?1:0);
//   if(dp[cnt][cur][msk] != -1) return dp[cnt][cur][msk];
//   dp[cnt][cur][msk] = 0;
//   REP(i,10){
//     if(msk&(1<<i))continue;
//     int nmsk = msk | (1<<i);
//     int ncur = cur - cnt*i;
//     if(ncur >= 0)
//       dp[cnt][cur][msk] += dfs(cnt-1,nmsk,ncur);
//   }
//   return dp[cnt][cur][msk];
// }

int main() {
  vi ar(10);
  REP(i, 10) ar[i] = i;
  do {
    int sum = 0;
    REP(i, 10) {
      sum += ar[i] * (i + 1);
      ++dp[i + 1][sum];
    }
  } while (next_permutation(ALL(ar)));
  int perm[11];
  perm[0] = 1;
  REPR(i, 11) perm[i] = perm[i - 1] * i;
  REPR(i, 11) REP(j, 353) dp[i][j] /= perm[10 - i];
  int n, s;
  while (~scanf("%d%d", &n, &s)) {
    if (n > 10 || s > 330) {
      cout << 0 << endl;
    } else {
      cout << dp[n][s] << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int, int> pii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = 1; i < n; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)

#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG_VEC(v)                                                           \\
  cout << #v << ":";                                                           \\
  REP(i, v.size()) cout << " " << v[i];                                        \\
  cout << endl
#define ALL(a) (a).begin(), (a).end()

#define MOD (ll)(1e9 + 7)
#define ADD(a, b) a = ((a) + (b)) % MOD
#define FIX(a) ((a) % MOD + MOD) % MOD

int dp[10][353][1252];

int dfs(int cnt, int msk, int cur) {
  if (cnt > 10 || cur > 330)
    return 0;
  if (cnt == 0)
    return (cur == 0 ? 1 : 0);
  if (dp[cnt][cur][msk] != -1)
    return dp[cnt][cur][msk];
  dp[cnt][cur][msk] = 0;
  REP(i, 10) {
    if (msk & (1 << i))
      continue;
    int nmsk = msk | (1 << i);
    int ncur = cur - cnt * i;
    if (ncur >= 0)
      dp[cnt][cur][msk] += dfs(cnt - 1, nmsk, ncur);
  }
  return dp[cnt][cur][msk];
}

int main() {
  REP(i, 10) REP(j, 353) REP(k, 1252) dp[i][j][k] = -1;
  while (cin) {
    int n, s;
    cin >> n >> s;
    cout << dfs(n, 0, s) << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int ok[11][1000];
int bit[1100][1000];

int bitcount(int a) {
  int i;
  for (i = 0; a; i++) {
    a &= a - 1;
  }
  return i;
}

int f(int a, int b) {
  int i;
  // cout<<a<<" "<<b<<endl;
  if (b < 0)
    return 0;
  if (bit[a][b] >= 0)
    return bit[a][b];
  if (a == 0)
    return 0;
  int res = 0;
  int bits = bitcount(a);
  for (i = 0; i < 10; i++) {
    if (a & 1 << i) {
      res += f(a ^ 1 << i, b - bits * i);
    }
  }
  bit[a][b] = res;
  return res;
}

int main() {
  int i, j;
  memset(bit, -1, sizeof(bit));
  bit[0][0] = 1;
  for (i = 0; i < 1 << 10; i++) {
    for (j = 0; j < 1000; j++) {
      f(i, j);
      ok[bitcount(i)][j] += bit[i][j];
    }
  }
  // cout<<"hoge"<<endl;
  /*	for(i=0;i<10;i++){
                  for(j=0;j<100;j++){
                          cout<<ok[i][j]<<" ";
                  }
                  cout<<endl;
          }
  */
  int n, s;
  while (cin >> n >> s) {
    cout << ok[n][s] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <class T> void chmin(T &t, T f) {
  if (t > f)
    t = f;
}
template <class T> void chmax(T &t, T f) {
  if (t < f)
    t = f;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

int n, s;

int f(int mask, int re, int i) {
  // cout<<"  "<<mask<<" "<<re<<" "<<i<<endl;
  if (i >= n + 1) {
    if (re == 0)
      return 1;
    else
      return 0;
  }
  if (re < 0)
    return 0;
  int res = 0;
  int k;
  for (k = 0; k < 10; k++) {
    if (mask & 1 << k)
      continue;
    // cout<<k<<" "<<re<<" "<<i<<endl;
    res += f(mask | 1 << k, re - k * i, i + 1);
  }
  return res;
}

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

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

#pragma warning(disable : 4996)

int n, s, dp[10][331][1024];

int rec(int depth, int ans, int bit) {
  if (depth == n)
    return s == ans ? 1 : 0;

  if (dp[depth][ans][bit] != -1) {
    return dp[depth][ans][bit];
  }

  int res = 0;

  for (int i = 0; i < 10; i++) {
    if (!(bit & (1 << i))) {
      res += rec(depth + 1, ans + (depth + 1) * i, bit + (1 << i));
    }
  }

  dp[depth][ans][bit] = res;

  return res;
}

int main() {
  while (~scanf("%d %d", &n, &s)) {
    memset(dp, -1, sizeof(dp));

    printf("%d\\n", rec(0, 0, 0));
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

#pragma warning(disable : 4996)

int n, s;

int rec(int depth, int ans, int bit) {
  if (depth == n)
    return s == ans ? 1 : 0;

  int res = 0;

  for (int i = 0; i < 10; i++) {
    if (!(bit & (1 << i))) {
      res += rec(depth + 1, ans + (depth + 1) * i, bit + (1 << i));
    }
  }

  return res;
}

int main() {
  while (~scanf("%d %d", &n, &s)) {
    printf("%d\\n", rec(0, 0, 0));
  }

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

#include <iostream>
#include <string.h>
using namespace std;

int numofbits(int bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

int main() {
  int n, s, dp[1024][400];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < 1024; ++i)
    for (int j = 0; j < 400; ++j)
      if (dp[i][j] != 0) {
        int t = numofbits(i) + 1;
        for (int k = 0; k < 10; ++k)
          if (!(1 << k & i)) {
            if (j + t * k >= 400)
              break;
            dp[i | 1 << k][j + t * k] += dp[i][j];
          }
      }

  while (cin >> n >> s) {
    int ans = 0;
    for (int i = 0; s < 400 && i < 1024; ++i)
      if (numofbits(i) == n)
        ans += dp[i][s];
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;

int numofbits(int bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

int main() {
  int n, s, dp[1024][400];
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < 1024; ++i)
    for (int j = 0; j < 400; ++j)
      if (dp[i][j] != -1) {
        int t = numofbits(i) + 1;
        for (int k = 0; k < 10; ++k)
          if (!(1 << k & i)) {
            if (j + t * k >= 400)
              break;
            dp[i | 1 << k][j + t * k] += dp[i][j];
          }
      }

  while (cin >> n >> s) {
    int ans = 0;
    for (int i = 0; i < 1024; ++i)
      if (numofbits(i) == n)
        ans += dp[i][s];
    cout << ans << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

const double EPS = 1e-10;

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

int go(int n, int s, int used) {
  if (n == 0) {
    return s == 0;
  }
  if (s < 0)
    return 0;
  if (s - 9 * n * n > 0)
    return 0;

  int res = 0;
  rep(i, 10) if (!(used & 1 << i)) {
    res += go(n - 1, s - n * i, used | 1 << i);
  }

  return res;
}

int main() {
  for (int n, s; cin >> n >> s;) {
    cout << go(n, s, 0) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

const double EPS = 1e-10;

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

int go(int n, int s, int used) {
  if (n == 0) {
    return s == 0;
  }
  if (s < 0)
    return 0;

  int res = 0;
  rep(i, 10) if (!(used & 1 << i)) {
    res += go(n - 1, s - n * i, used | 1 << i);
  }

  return res;
}

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

// AOJ 0070
#include <iostream>
using namespace std;

int solve(int n, int s, long long int available) {
  if (s > (n + 1) * n / 2 * 9)
    return 0;

  if (n == 1) {
    return ((0 <= s && s < 10 && (available >> s) & 1) ? 1 : 0);
  } else {
    int sum = 0;
    for (int i = 0, mxm = s / n; i <= mxm; i++) {
      if ((available >> i) & 1) {
        int v = solve(n - 1, s - n * i, available & ~(1 << i));
        sum += v;
      }
    }
    return sum;
  }
}

int main() {
  int n, s;
  while (cin >> n >> s) {
    cout << solve(n, s, (1 << 10) - 1) << endl;
  }
}

Error: TLE

Fixed submission:

// AOJ 0070
#include <iostream>
using namespace std;

int solve(int n, int s, int available) {
  if (n == 0) {
    return 0;
  } else if (n == 1) {
    return (0 <= s && s < 10 ? 1 : 0);
  } else {
    int sum = 0;
    for (int i = 0, mxm = s / n; i < mxm; i++) {
      if ((available >> i) & 1) {
        sum += solve(n - 1, s - n * i, available & ~(1 << n));
      }
    }
    return sum;
  }
}

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

// AOJ 0070
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int integer;

const integer NMAX = 20, SMAX = 1000;
integer dp[NMAX][SMAX], factorial[NMAX];

void solve() {
  factorial[0] = 1;
  for (int i = 1; i <= 10; i++) {
    factorial[i] = i * factorial[i - 1];
  }

  int nums[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  do {
    integer sum = 0;
    REP(i, 10) {
      sum += nums[i] * (i + 1);
      dp[i + 1][sum]++;
    }
  } while (next_permutation(nums, nums + 10));
}

int main() {
  solve();

  int n, s;
  while (cin >> n >> s) {
    cout << dp[n][s] / factorial[10 - n] << endl;
  }
}

Error: 0

Fixed submission:

// AOJ 0070
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int integer;

const integer NMAX = 11, SMAX = 1000;
integer dp[NMAX][SMAX], factorial[NMAX];

void solve() {
  factorial[0] = 1;
  for (int i = 1; i <= 10; i++) {
    factorial[i] = i * factorial[i - 1];
  }

  int nums[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  do {
    integer sum = 0;
    REP(i, 10) {
      sum += nums[i] * (i + 1);
      dp[i + 1][sum]++;
    }
  } while (next_permutation(nums, nums + 10));
}

int main() {
  solve();

  int n, s;
  while (cin >> n >> s) {
    cout << dp[n][s] / factorial[10 - n] << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;
#define INF 1000000
int s1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int L, ans = 0, s;

void Permutation(int s2[], int t, int num) {
  if (num == L) {
    if (t == s)
      ans++;
  } else {
    if (t > s)
      return;
    for (int i = 0; i < 10 - num; i++) {
      int a = s2[i];
      s2[i] = s2[10 - num - 1];
      Permutation(s2, t + (num + 1) * a, num + 1);
      s2[10 - num - 1] = s2[i];
      s2[i] = a;
    }
  }
}
int main() {
  while (cin >> L >> s) {
    ans = 0;
    Permutation(s1, 0, 0);
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;
#define INF 1000000
int s1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, t1[10];
int s;
int L, ans = 0;
void check() {
  int sum = 0;
  for (int i = 0; i < L; i++) {
    sum += (i + 1) * t1[i];
  }
  if (s == sum) {
    ans++;
  }
}
void Permutation(int s[], int t[], int num) {
  if (num == L) {
    check();

  } else {
    for (int i = 0; i < 10 - num; i++) {
      t[num] = s[i];
      int a = s[i];
      s[i] = s[10 - num - 1];
      Permutation(s, t, num + 1);
      s[10 - num - 1] = s[i];
      s[i] = a;
    }
  }
}
int main() {
  while (cin >> L >> s) {
    ans = 0;
    Permutation(s1, t1, 0);
    cout << ans << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
using namespace std;

int ans[11][410];

void dfs(int dpt, int sum, int bit) {
  ++ans[dpt][sum];
  for (int i = 0; i < 10; ++i) {
    if (bit >> i & 1) {
      dfs(dpt + 1, sum + i * (dpt + 1), bit ^ (1 << i));
    }
  }
}

int main() {
  dfs(0, 0, 0x3ff);
  int n, s;
  while (scanf("%d%d", &n, &s) != EOF) {
    int x = 0;
    if (n <= 10 && s <= 400) {
      x = ans[n][s];
    }
    printf("%d\\n", x);
  }
}

Error: 0

Fixed submission:

#include <cstdio>
using namespace std;

int ans[11][410];

void dfs(int dpt, int sum, int bit) {
  ++ans[dpt][sum];
  for (int i = 0; i < 10; ++i) {
    if (bit >> i & 1) {
      dfs(dpt + 1, sum + i * (dpt + 1), bit ^ (1 << i));
    }
  }
}

int main() {
  dfs(0, 0, 0x3ff);
  int n, s;
  while (scanf("%d%d", &n, &s) != EOF) {
    int x = 0;
    x = ans[n][s];
    if (n <= 10 && s <= 400) {
      x = ans[n][s];
    }
    printf("%d\\n", x);
  }
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
const int N_MAX = 10;
const int S_MAX = 330;
int results[N_MAX + 1][S_MAX + 1];
bool used[10 + 1];
int i;

void permutations(int p, int sum) {
  if (p == 0) {
    results[i][sum]++;
  } else {
    for (int i = 0; i < 10; i++) {
      if (used[i])
        continue;
      used[i] = true;
      permutations(p - 1, sum + i * p);
      used[i] = false;
    }
  }
}

int main() {
  for (i = 1; i <= 10; i++) {
    memset(results, 0, sizeof(0));
    permutations(i, 0);
  }
  int n, s;
  while (cin >> n >> s) {
    if (s > S_MAX)
      cout << 0 << endl;
    else
      cout << results[n][s] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
const int N_MAX = 10;
const int S_MAX = 330;
int results[N_MAX + 1][S_MAX + 1];
bool used[10 + 1];
int i;

void permutations(int p, int sum) {
  if (p == 0) {
    results[i][sum]++;
  } else {
    for (int i = 0; i < 10; i++) {
      if (used[i])
        continue;
      used[i] = true;
      permutations(p - 1, sum + i * p);
      used[i] = false;
    }
  }
}

int main() {
  for (i = 1; i <= 10; i++) {
    memset(results, 0, sizeof(0));
    permutations(i, 0);
  }
  int n, s;
  while (cin >> n >> s) {
    cout << results[n][s] << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int number[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
long long int dp[10][10001];

long long int factorial(int x) {
  long long int ret = 1;
  for (int i = 1; i <= x; i++)
    ret *= i;
  return ret;
}

int main() {
  do {
    int sum = 0;
    for (int i = 0; i < 10; i++) {
      sum += number[i] * (i + 1);
      dp[i][sum]++;
    }
  } while (next_permutation(number, number + 10));

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

Error: TLE

Fixed submission:

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

int number[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
long long int dp[10][10001];

long long int factorial(int x) {
  long long int ret = 1;
  for (int i = 1; i <= x; i++)
    ret *= i;
  return ret;
}

int main() {
  do {
    int sum = 0;
    for (int i = 0; i < 10; i++) {
      sum += number[i] * (i + 1);
      dp[i][sum]++;
    }
  } while (next_permutation(number, number + 10));

  int n, s;
  while (cin >> n >> s, n + s) {
    cout << dp[n - 1][s] / factorial(10 - n) << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

void solve(int c, int sum);

int n, s, list[11][331], judge[10];
int main() {
  solve(1, 0);
  while (cin >> n >> s) {
    if (n > 10 || s > 330) {
      n = 0;
      s = 0;
    }
    cout << list[n][s] << endl;
  }
  return 0;
}

void solve(int c, int sum) {
  if (c == 11)
    return;
  for (int i = 0; i < 10; i++) {
    if (!judge[i]) {
      judge[i] = 1;
      ++list[c][sum + i * c];
      solve(c + 1, sum + i * c);
      judge[i] = 0;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int solve(int i, int sum, int flag);

int s, n;
int main() {
  while (!cin.eof()) {
    cin >> n >> s;
    s = solve(0, 0, 0);
    cout << s << endl;
  }
  return 0;
}

int solve(int i, int sum, int flag) {
  int res = 0;
  if (i == n && sum == s)
    ++res;
  else {
    for (int k = 0; k < 10; k++) {
      if (flag & 1 << k)
        continue;
      res += solve(i + 1, sum + k * (i + 1), flag | 1 << k);
    }
  }
  return res;
}