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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
#define int long long
#define str string
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
  ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
  ll to, cost;
};
ll gcm(ll i, ll j) { //?????§??¬?´???°
  if (i > j)
    swap(i, j);
  if (i == 0)
    return j;
  return gcm(j % i, i);
}

//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, s;
int dp[11][331][1024];
signed main() {
  dp[0][0][0] = 1;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 331; j++)
      for (int z = 0; z < 1024; z++)
        if (dp[i][j][z] > 0)
          for (int x = 0; x < 10; x++)
            if (!((1 << x) & z))
              dp[i + 1][j + x * (i + 1)][z | (1 << x)] += dp[i][j][z];
  while (cin >> n >> s) {
    if (s > 330) {
      cout << 0 << endl;
      continue;
    }
    int ans = 0;
    for (int i = 0; i < 1024; i++)
      ans += dp[n][s][i];
    cout << ans << endl;
  }
  // getchar(); getchar();
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
#define int long long
#define str string
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
  ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
  ll to, cost;
};
ll gcm(ll i, ll j) { //?????§??¬?´???°
  if (i > j)
    swap(i, j);
  if (i == 0)
    return j;
  return gcm(j % i, i);
}

//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, s;
int dp[11][331][1024];
signed main() {
  dp[0][0][0] = 1;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 331; j++) {
      for (int z = 0; z < 1024; z++) {
        for (int x = 0; x < 10; x++) {
          if (!(z & (1 << x))) {
            dp[i + 1][j + x * (i + 1)][z | 1 << x] += dp[i][j][z];
          }
        }
      }
    }
  }
  while (cin >> n >> s) {
    if (s > 330) {
      cout << 0 << endl;
      continue;
    }
    int ans = 0;
    for (int i = 0; i < 1024; i++)
      ans += dp[n][s][i];
    cout << ans << endl;
  }
  // getchar(); getchar();
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n, s;
typedef pair<pi, int> T;
map<T, int> M;

int f(int n, int s, int S) {
  if (!n)
    return !s;
  if (M.find(T(pi(n, s), S)) != M.end())
    return M[T(pi(n, s), S)];
  int &r = M[T(pi(n, s), S)];
  rep(i, 10) if (!(S & 1 << i) && s >= n * i) r +=
      f(n - 1, s - n * i, S | 1 << i);
  return r;
}

int main() {
  while (cin >> n >> s) {
    cout << f(n, s, 0) << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n, s;
typedef pair<pi, int> T;
map<T, int> M;

int f(int m, int s, int S) {
  if (m == n + 1)
    return !s;
  if (M.find(T(pi(m, s), S)) != M.end())
    return M[T(pi(m, s), S)];
  int &r = M[T(pi(m, s), S)];
  rep(i, 10) if (!(S & 1 << i) && s >= m * i) r +=
      f(m + 1, s - m * i, S | 1 << i);
  return r;
}

int main() {
  while (cin >> n >> s) {
    M.clear();
    cout << f(1, s, 0) << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define f first
#define s second
#define mp make_pair

#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()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

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

int ans(int cnt, int f, int s) {
  if (s < 0)
    return 0;
  if (memo[f][s] != -1)
    return memo[f][s];
  if ((cnt == 1) && (s < 10) && ((f & (1 << s)) != 0))
    return memo[f][s] = 1;
  int ret = 0;
  for (int i = 9; i >= 0; i--)
    if ((f & (1 << i)) != 0)
      ret += ans(cnt - 1, f ^ (1 << i), s - i * cnt);
  return memo[f][s] = ret;
}

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

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define f first
#define s second
#define mp make_pair

#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()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

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

int ans(int cnt, int f, int s) {
  if (s < 0)
    return 0;
  if (memo[f][s] != -1)
    return memo[f][s];
  if ((cnt == 1) && (s < 10) && ((f & (1 << s)) != 0))
    return memo[f][s] = 1;
  int ret = 0;
  for (int i = 9; i >= 0; i--)
    if ((f & (1 << i)) != 0)
      ret += ans(cnt - 1, f ^ (1 << i), s - i * cnt);
  return memo[f][s] = ret;
}

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

#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int dp[1 << 11][11][333];
int solve(int bit, int i, int sum) {
  if (i >= 11)
    return 0;
  if (sum > 330)
    return 0;
  if (!i)
    return (sum) ? 0 : 1;
  if (dp[bit][i][sum] >= 0)
    return dp[bit][i][sum];
  int ret = 0;
  for (int j = 0; j < 10; j++) {
    if (bit & 1 << j)
      continue;
    ret += solve(bit | 1 << j, i - 1, sum - j * i);
  }
  return dp[bit][i][sum] = ret;
}
int main(void) {
  int n, s;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> s) {
    cout << solve(0, n, s) << endl;
  }
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
map<pair<int, pair<int, int>>, int> dp;
int solve(int bit, int i, int sum) {
  if (!i)
    return (sum) ? 0 : 1;
  if (dp.find(make_pair(bit, make_pair(i, sum))) != dp.end())
    return dp[make_pair(bit, make_pair(i, sum))];
  int ret = 0;
  for (int j = 0; j < 10; j++) {
    if (bit & 1 << j)
      continue;
    ret += solve(bit | 1 << j, i - 1, sum - j * i);
  }
  return dp[make_pair(bit, make_pair(i, sum))] = ret;
}
int main(void) {
  int n, s;
  while (cin >> n >> s) {
    cout << solve(0, n, s) << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int ans[11][331];
int used[10];

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

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

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int ans[11][331];
int used[10];

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

int main() {
  calc(1, 0);
  int n, s;
  while (cin >> n >> s) {
    cout << ans[n][s] << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

bool used[10];

int table[15][1050][1 << 10];
int z = (1 << 10) - 1;
int solve(int x, int y) {
  if (x > 10)
    return 0;
  if (x < 0)
    return 0;
  if (y > 1050)
    return 0;
  if (y < 0)
    return 0;
  int &res = table[x][y][z];
  if (res != -1)
    return res;
  res = 0;
  if (x == 0)
    return res = (y == 0);
  for (int i = 0; i < 10; i++) {
    if (used[i])
      continue;
    used[i] = true;
    z ^= 1 << i;
    res += solve(x - 1, y - x * i);
    z ^= 1 << i;
    used[i] = false;
  }
  return res;
}

int main() {
  for (int i = 0; i < 15; i++)
    for (int j = 0; j < 1050; j++)
      for (int k = 0; k < (1 << 10); k++)
        table[i][j][k] = -1;
  int n, s;
  while (cin >> n >> s)
    cout << solve(n, s) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

bool used[10];

int solve(int x, int y) {
  if (x == 0)
    return y == 0;
  if (y < 0)
    return 0;
  int res = 0;
  for (int i = 0; i < 10; i++) {
    if (used[i])
      continue;
    used[i] = true;
    res += solve(x - 1, y - x * i);
    used[i] = false;
  }
  return res;
}

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 <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int num[10];
int dp[11][331];
int fact[11];

signed main() {
  rep(i, 0, 10) num[i] = i;
  do {
    int t = 0;
    rep(i, 0, 10) {
      t += num[i] * (i + 1);
      dp[i + 1][t]++;
    }
  } while (next_permutation(num, num + 10));

  fact[0] = 1;
  rep(i, 1, 10) fact[i] = fact[i - 1] * i;

  int n, s;
  while (cin >> n >> s) {
    if (s > 331 || n > 10) {
      o(0);
      continue;
    }
    o(dp[n][s] / fact[10 - n]);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int dp[11][331][1 << 10] = {};

signed main() {
  int n, s;
  while (cin >> n >> s) {
    if (s > 331 || n > 10) {
      o(0);
      continue;
    }
    rep(i, 0, 11) rep(j, 0, 331) rep(k, 0, 1 << 10) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    rep(i, 1, n + 1) {
      rep(j, 0, 331) {
        rep(k, 0, 1 << 10) {
          rep(l, 0, 10) {
            if (j + l * i >= 400 || dp[i - 1][j][k] == 0 || (k & 1 << l))
              continue;
            dp[i][j + l * i][k | 1 << l] += dp[i - 1][j][k];
          }
        }
      }
    }
    int ans = 0;
    rep(i, 0, 1 << 10) { ans += dp[n][s][i]; }
    o(ans);
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool flags[10];
int solved[1024][331];

int trans() {
  int a = 0;
  for (int i = 0; i < 10; i++)
    a += (int(flags[i]) << i);
  return a;
}

int solve(int index, int sum, int max) {
  int a = trans();
  if (sum < 0 || sum > 330 || index > max) {
    return 0;
  }
  if (index == max && sum == 0) {
    return solved[a][0] = 1;
  }

  if (solved[a][sum] != -1)
    return solved[a][sum];
  int count = 0;
  for (int i = 0; i < 10; i++) {
    if (!flags[i]) {
      flags[i] = true;
      int s = solve(index + 1, sum - index * i, max);
      count += s;
      flags[i] = false;
    }
  }
  return solved[a][sum] = count;
}

int main() {
  int n, s;
  while (cin >> n >> s) {
    for (int i = 0; i < 1024; i++)
      for (int j = 0; j < 331; j++)
        solved[i][j] = -1;
    cout << solve(1, s, n + 1) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool flags[10];

int solve(int index, int sum, int max) {
  if (index > max)
    return 0;
  if (index == max && sum == 0) {
    return 1;
  }
  if (sum < 0)
    return 0;

  int count = 0;
  for (int i = 0; i < 10; i++) {
    if (!flags[i]) {
      flags[i] = true;
      int s = solve(index + 1, sum - index * i, max);
      count += s;
      flags[i] = false;
    }
  }
  return count;
}

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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#define all(a) a.begin(), a.end()
using namespace std;

typedef vector<int> vi;
struct hoge {
  int a[10];
  hoge() { memset(a, 0, sizeof a); }
};

int n, s;
int memo[20][1000] = {};

int calc(hoge v, int val, int size) {
  if (size > 10)
    return 0;
  memo[size][val]++;

  int ans = 0;
  for (int i = 0; i <= 9; i++) {
    if (!v.a[i]) {
      v.a[i] = true;
      ans += calc(v, val + i * (size + 1), size + 1);
      v.a[i] = false;
    }
  }
  return ans;
}

int main() {
  hoge x;
  calc(x, 0, 0);
  while (cin >> n >> s) {
    cout << memo[min(n, 19)][min(s, 999)] << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#define all(a) a.begin(), a.end()
using namespace std;

typedef vector<int> vi;
struct hoge {
  int a[10];
  hoge() { memset(a, 0, sizeof a); }
};

int n, s;
int memo[11][300] = {};

int calc(hoge v, int val, int size) {
  if (size > 10)
    return 0;
  memo[size][val]++;

  int ans = 0;
  for (int i = 0; i <= 9; i++) {
    if (!v.a[i]) {
      v.a[i] = true;
      ans += calc(v, val + i * (size + 1), size + 1);
      v.a[i] = false;
    }
  }
  return ans;
}

int main() {
  hoge x;
  calc(x, 0, 0);
  while (cin >> n >> s) {
    cout << memo[n][s] << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

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

int cnt[11][1000];
void f(bitset<10> used, int d, int s) {
  cnt[d][s]++;
  for (int i = 0; i < 10; ++i) {
    if (!used[i]) {
      used.set(i);
      f(used, d + 1, s + i * (d + 1));
      used.reset(i);
    }
  }
}

int main() {
  f(bitset<10>(), 0, 0);
  int n, s;
  while (cin >> n >> s) {
    if (s > 1000)
      cout << 0 << endl;
    else
      cout << cnt[n][s] << endl;
  }
}

Error: TLE

Fixed submission:

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

int cnt[11][1000];
bitset<10> used;
void f(int d, int s) {
  cnt[d][s]++;
  for (int i = 0; i < 10; ++i) {
    if (!used[i]) {
      used.set(i);
      f(d + 1, s + i * (d + 1));
      used.reset(i);
    }
  }
}

int main() {
  f(0, 0);
  int n, s;
  while (cin >> n >> s)
    cout << cnt[n][s] << endl;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

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

int res[10][1000];

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

  sort(v.begin(), v.end());
  int mx = 0;
  do {
    int tmp = 0;
    for (int j = 0; j < 10; j++) {
      tmp += v[j] * (1 + j);
      res[j][tmp]++;
    }
  } while (next_permutation(v.begin(), v.end()));

  int fact = 1;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 1000; j++) {
      res[9 - i][j] /= fact;
    }
    fact *= (i + 1);
  }

  int n, s;
  while (cin >> n >> s) {
    if (n == 0 || n > 10 || s >= 1000)
      cout << 0 << endl;
    else
      cout << res[n - 1][s] << endl;
  }
}

Error: 0

Fixed submission:

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

int res[10][1000];

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

  sort(v.begin(), v.end());
  do {
    int tmp = 0;
    for (int j = 0; j < 10; j++) {
      tmp += v[j] * (1 + j);
      res[j][tmp]++;
    }
  } while (next_permutation(v.begin(), v.end()));

  int fact = 1;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 1000; j++) {
      res[9 - i][j] /= fact;
    }
    fact *= (i + 1);
  }

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

#include <stdio.h>

int x(int n, int s, int k[]) {
  int kcpy[10];
  int i, j;
  int cnt = 0;
  if (n * (n + 1) * (31 - n) >= 6 * s && 6 * s >= n * n * n - n) {
    if (n - 1) {
      for (i = 0; i < 10; i++) {
        kcpy[i] = k[i];
      }
      for (j = 0; j < 10 && j * n <= s; j++) {
        if (kcpy[j]) {
          kcpy[j] = 0;
          cnt += x(n - 1, s - j * n, kcpy);
          kcpy[j] = 1;
        }
      }
    } else if (s < 10) {
      cnt = k[s];
    }
  }
  return cnt;
}

int main() {
  int y = 0, n, s;
  int k[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  while (scanf("%d %d", &n, &s) != EOF) {
    y = x(n, s, k);
    printf("%d\\n", y);
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

int x(int n, int s, int k[]) {
  int kcpy[10];
  int i, j;
  int cnt = 0;
  if (6 * s >= n * n * n - n) {
    if (n - 1) {
      for (i = 0; i < 10; i++) {
        kcpy[i] = k[i];
      }
      for (j = 0; j < 10 && j * n <= s; j++) {
        if (kcpy[j]) {
          kcpy[j] = 0;
          cnt += x(n - 1, s - j * n, kcpy);
          kcpy[j] = 1;
        }
      }
    } else if (s < 10) {
      cnt = k[s];
    }
  }
  return cnt;
}

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n, s;
int memo[11][1024][400];

int solve(int t, int state, int sum) {
  if (sum < 0)
    return 0;
  if (t == n + 1)
    return sum == 0;
  if (memo[t][state][sum] != -1)
    return memo[t][state][sum];
  int answer = 0;
  for (int i = 0; i < 10; ++i) {
    if (state & (1 << i))
      continue;
    answer += solve(t + 1, state | (1 << i), sum - i * t);
  }
  return memo[t][state][sum] = answer;
}

int main() {
  int prev = -1;
  while (scanf("%d%d", &n, &s) != EOF) {
    if (prev == n)
      goto output;
    for (int i = 0; i < 11; ++i) {
      for (int j = 0; j < 1024; ++j) {
        for (int k = 0; k < 400; ++k) {
          memo[i][j][k] = -1;
        }
      }
    }
  output:;
    printf("%d\\n", (s > 400 ? 0 : solve(1, 0, s)));
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n, s;
int memo[11][1024][400];

int solve(int t, int state, int sum) {
  if (memo[t][state][sum] != -1)
    return memo[t][state][sum];
  if (sum < 0)
    return 0;
  if (t == n + 1)
    return sum == 0;
  int answer = 0;
  for (int i = 0; i < 10; ++i) {
    if (state & (1 << i))
      continue;
    answer += solve(t + 1, state | (1 << i), sum - i * t);
  }
  return memo[t][state][sum] = answer;
}

int main() {
  for (int i = 0; i < 11; ++i) {
    for (int j = 0; j < 1024; ++j) {
      for (int k = 0; k < 400; ++k) {
        memo[i][j][k] = -1;
      }
    }
  }
  while (scanf("%d%d", &n, &s) != EOF) {
    printf("%d\\n", (s > 400 ? 0 : solve(1, 0, s)));
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string.h>
#include <string>

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

using namespace std;

int dp[10][330];
int flag[10];

void dfs(int i, int a) {
  if (a > 330 || i > 10) {
    return;
  } else {
    rep(k, 10) {
      if (flag[k] == 0) {
        flag[k] = 1;
        int temp = i * k;
        dp[i][a + temp]++;
        dfs(i + 1, a + temp);
        flag[k] = 0;
      }
    }
  }
}

int main() {
  int n, s;
  memset(flag, 0, sizeof(flag));
  dfs(1, 0);
  while (cin >> n >> s) {
    if (s > 330) {
      cout << 0 << endl;
    } else {
      cout << dp[n][s] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string.h>
#include <string>

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

using namespace std;

int dp[10][330];
int flag[10];

void dfs(int i, int a) {
  if (a > 330 || i > 10) {
    return;
  } else {
    rep(k, 10) {
      if (flag[k] == 0) {
        flag[k] = 1;
        int temp = i * k;
        dp[i][a + temp]++;
        dfs(i + 1, a + temp);
        flag[k] = 0;
      }
    }
  }
}

int main() {
  int n, s;
  while (cin >> n >> s) {
    if (s > 330) {
      cout << 0 << endl;
    } else {
      memset(flag, 0, sizeof(flag));
      memset(dp, 0, sizeof(dp));
      dfs(1, 0);
      cout << dp[n][s] << endl;
    }
  }
  return 0;
}