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

#include <iostream>
#define INF 99999999
using namespace std;
int n, s, cnt;

int dp[(1 << 10) + 1][1000][11];

int rec(int S, int sum, int cnt) {
  if (sum < 0 || sum > 1000 || cnt < 0 || cnt > 10)
    return 0;
  if (dp[S][sum][cnt] != INF)
    return dp[S][sum][cnt];

  if (cnt == 0) {
    if (sum == 0)
      return 1;
    else
      return 0;
  }

  int res = 0, x = 0;
  for (int i = 0; i < 10; i++) {
    if ((S >> i) & 1)
      x++;
  }

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

int main() {
  for (int i = 0; i < (1 << 10) + 1; i++) {
    for (int j = 0; j < 1000; j++)
      for (int k = 0; k < 11; k++)
        dp[i][j][k] = INF;
  }
  while (cin >> n >> s) {
    cout << rec(0, s, n) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#define INF 99999999
using namespace std;
int n, s, cnt;

int dp[(1 << 10) + 1][1000][11];

int rec(int S, int sum, int cnt) {
  if (sum < 0 || cnt < 0)
    return 0;
  if (dp[S][sum][cnt] != INF)
    return dp[S][sum][cnt];

  if (cnt == 0) {
    if (sum == 0)
      return 1;
    else
      return 0;
  }

  int res = 0, x = 0;
  for (int i = 0; i < 10; i++) {
    if ((S >> i) & 1)
      x++;
  }

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

int main() {
  for (int i = 0; i < (1 << 10) + 1; i++) {
    for (int j = 0; j < 1000; j++)
      for (int k = 0; k < 11; k++)
        dp[i][j][k] = INF;
  }
  while (cin >> n >> s) {
    cout << rec(0, s, n) << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define loop for (;;)
#define trace(var) cerr << ">>> " << #var << " = " << var << endl;
#define all(v) begin(v), end(v)
#define pb push_back
#define inf (1e9)
#define eps (1e-9)

typedef long long Integer;
typedef long double Real;
const Real PI = acosl(-1);
typedef pair<int, int> P;

template <class S, class T>
inline ostream &operator<<(ostream &os, pair<S, T> p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class S, class T, class U>
inline ostream &operator<<(ostream &os, tuple<S, T, U> t) {
  return os << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t)
            << ')';
}

template <class T> inline ostream &operator<<(ostream &os, set<T> v) {
  os << "(set";
  for (T item : v)
    os << ' ' << item;
  os << ")";
  return os;
}

template <class T> inline ostream &operator<<(ostream &os, vector<T> v) {
  if (v.size() == 0) {
    return os << "(empty)";
  }
  os << v[0];
  for (int i = 1, len = v.size(); i < len; ++i)
    os << ' ' << v[i];
  return os;
}

template <class T> inline istream &operator>>(istream &is, vector<T> &v) {
  rep(i, v.size()) is >> v[i];
  return is;
}

//           ^   >  v   <
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<bool> vb;

int table[11][10000];
int memo[10];

void f(int size, int depth, int sum) {
  if (size + 1 == depth) {
    table[size][sum]++;
  } else {
    rep(i, 10) {
      if (memo[i] == 0) {
        memo[i] = 1;
        f(size, depth + 1, sum + i * depth);
        memo[i] = 0;
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);
  cout.precision(10);
  random_device dev;
  mt19937 rand(dev());

  rep(i, 10) {
    memset(memo, 0, sizeof(memo));
    f(i + 1, 1, 0);
  }

  int n, s;
  while (cin >> n >> s)
    cout << table[n][s] << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define loop for (;;)
#define trace(var) cerr << ">>> " << #var << " = " << var << endl;
#define all(v) begin(v), end(v)
#define pb push_back
#define inf (1e9)
#define eps (1e-9)

typedef vector<int> vi;

int solve(int n, int s) {
  vi xs(10);
  vi ys(n);
  rep(i, 10) xs[i] = i;
  set<vi> aa;
  do {
    int t = 0;
    rep(i, n) {
      t += xs[i] * (i + 1);
      ys[i] = xs[i];
    }
    if (t == s) {
      aa.insert(ys);
    }
  } while (next_permutation(all(xs)));
  return aa.size();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout.setf(ios::fixed);

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

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

#include <iostream>
using namespace std;

int bit_one(int b) {
  int r = 0;
  while (b) {
    r += b % 2;
    b >>= 1;
  }
  return r;
}

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

void set() {
  for (int i = 0; i < 300; i++) {
    for (int j = 0; j < (1 << 10); j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for (int i = 0; i < 300; i++) {
    for (int j = 0; j < (1 << 10); j++) {
      for (int k = 0; k < 10; k++) {
        if (dp[i][j] && (j >> k) % 2 == 0) {
          dp[i + k * (bit_one(j) + 1)][j | (1 << k)] += dp[i][j];
        }
      }
    }
  }
}

int main() {
  set();
  int n, s;
  while (cin >> n >> s) {
    if (s >= 400) {
      cout << 0 << endl;
      continue;
    }
    int ans = 0;
    for (int i = 0; i < (1 << 10); i++) {
      if (bit_one(i) == n) {
        ans += dp[s][i];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int bit_one(int b) {
  int r = 0;
  while (b) {
    r += b % 2;
    b >>= 1;
  }
  return r;
}

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

void set() {
  for (int i = 0; i < 300; i++) {
    for (int j = 0; j < (1 << 10); j++) {
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  for (int i = 0; i < 300; i++) {
    for (int j = 0; j < (1 << 10); j++) {
      for (int k = 0; k < 10; k++) {
        if (dp[i][j] && (j >> k) % 2 == 0) {
          dp[i + k * (bit_one(j) + 1)][j | (1 << k)] += dp[i][j];
        }
      }
    }
  }
}

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

#include <algorithm>
#include <iostream>
using namespace std;
int dp[10][1 << 10][331],
    n; // n?????¶?´??????????????????? s???????????????(ry ??? 331???
int rec(int now, int used, int sum) {
  if (sum < 0)
    return 0;
  if (now == n)
    return sum == 0;
  if (~dp[now][used][sum])
    return dp[now][used][sum];
  int ret = 0;
  for (int i = 0; i < 10; i++) {
    if ((used >> i) & 1)
      ret += rec(now + 1, used & ~(1 << i), sum - i * (now + 1));
  }
  return dp[now][used][sum] = ret;
}
int main() {
  int s;
  while (cin >> n >> s) {
    fill_n(**dp, 10 * (1 << 10) * 331, -1);
    cout << rec(0, (1 << 10) - 1, s) << endl;
  }
}

Error: TLE

Fixed submission:

// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i > (b); i--)
#define REP(i, n) FOR(i, 0, n)

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

void print_arr(int arr[10]) {
  cout << "----------------------------" << endl;
  REP(i, 10) cout << arr[i] << ", ";
  cout << endl;
}

// debug
//-------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;
int N = 0;
int S = 0;
int result = 0;
int memo[1 << 10][332][11];
int dfs(int used, int sum, int n) {
  if (sum < 0)
    return 0;
  if (n == N + 1) {
    if (sum == 0) {
      return 1;
    }
    return 0;
  }

  if (memo[used][sum][n] >= 0) {
    return memo[used][sum][n];
  }
  int res = 0;

  for (int i = 0; i < 10; i++) {
    if ((used >> i) & 1) {
      res += dfs(used & ~(1 << i), sum - n * i, n + 1);
    }
  }

  return memo[used][sum][n] = res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  memset(memo, -1, sizeof(memo));
  int n, s;
  while (1) {
    cin >> n >> s;
    N = n;
    if (s >= 331) {
      cout << 0 << endl;
      continue;
    }
    if (cin.eof())
      break;
    cout << dfs((1 << 10) - 1, s, 1) << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int dp[1024][500];

int main() {
  int n, s;
  dp[0][0] = 1;
  for (int i = 0; i < 350; i++) {
    for (int j = 0; j < 1024; j++) {
      int cnt = 1;
      for (int k = 0; k < 10; k++)
        if (j & (1 << k))
          cnt++;
      for (int k = 0; k < 10; k++) {
        if (j & (1 << k))
          continue;
        dp[j | (1 << k)][i + cnt * k] += dp[j][i];
      }
    }
  }
  while (cin >> n >> s) {
    int res = 0;
    for (int i = 0; i < 1024; i++) {
      if (s > 400)
        continue;
      int c = 0;
      for (int j = 0; j < 10; j++)
        if (i & (1 << j))
          c++;
      if (c == n)
        res += dp[i][s];
    }
    cout << res << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int dp[1024][500];

int main() {
  int n, s;
  dp[0][0] = 1;
  for (int i = 0; i < 350; i++) {
    for (int j = 0; j < 1024; j++) {
      int cnt = 1;
      for (int k = 0; k < 10; k++)
        if (j & (1 << k))
          cnt++;
      for (int k = 0; k < 10; k++) {
        if (j & (1 << k))
          continue;
        dp[j | (1 << k)][i + cnt * k] += dp[j][i];
      }
    }
  }
  while (cin >> n >> s) {
    int res = 0;
    for (int i = 0; i < 1024; i++) {
      int c = 0;
      for (int j = 0; j < 10; j++)
        if (i & (1 << j))
          c++;
      if (c == n)
        res += dp[i][s];
    }
    cout << res << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int n, s, x, a[10], e[11], c, i, j, m;
  int l[] = {9, 26, 50, 80, 115, 154, 196, 240, 285, 330};
  while (~scanf("%d%d", &n, &s)) {
    x = c = m = 0;
    for (i = 0; i < 11; i++)
      e[i] = 0;
    for (i = 0; i < n; i++) {
      a[i] = n - i - 1;
      e[a[i]] = 1;
      x += a[i] * (i + 1);
    }
    if (s > 330)
      m = n;
    do {
      if (x == s)
        c++;
      if (x >= s)
        m++;
      for (i = 0; i < n; i++) {
        x -= a[i] * (i + 1);
        e[a[i]] = 0;
        if (i < m)
          continue;
        if (i == 0)
          a[i] = (s - x < 10 && !e[s - x] ? s - x : 10);
        else
          do {
            a[i]++;
          } while (e[a[i]]);
        if (a[i] > 9) {
          m++;
          continue;
        }
        if (s - x > l[m]) {
          while (s - x > l[m])
            m++;
          continue;
        }
        e[a[i]] = 1;
        x += a[i] * (i + 1);
        for (i--; i >= 0; i--) {
          for (j = 0; j < 10; j++) {
            if (e[j])
              continue;
            a[i] = j;
            e[a[i]] = 1;
            x += a[i] * (i + 1);
            break;
          }
        }
        if (x > s) {
          m++;
          if (m >= n)
            break;
          continue;
        }
        m = 0;
        break;
      }
    } while (m < n);
    printf("%d\\n", c);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int n, s, x, a[10], e[11], c, i, j, m;
  while (~scanf("%d%d", &n, &s)) {
    x = c = m = 0;
    for (i = 0; i < 11; i++)
      e[i] = 0;
    for (i = 0; i < n; i++) {
      a[i] = n - i - 1;
      e[a[i]] = 1;
      x += a[i] * (i + 1);
    }
    do {
      if (x == s)
        c++;
      if (x >= s)
        m++;
      for (i = 0; i < n; i++) {
        x -= a[i] * (i + 1);
        e[a[i]] = 0;
        if (i < m)
          continue;
        do {
          a[i]++;
        } while (e[a[i]]);
        if (a[i] > 9) {
          m++;
          continue;
        }
        e[a[i]] = 1;
        x += a[i] * (i + 1);
        for (i--; i >= 0; i--) {
          for (j = 0; j < 10; j++) {
            if (e[j])
              continue;
            a[i] = j;
            e[a[i]] = 1;
            x += a[i] * (i + 1);
            break;
          }
        }
        if (x > s) {
          m++;
          if (m >= n)
            break;
          continue;
        }
        m = 0;
        break;
      }
    } while (m < n);
    printf("%d\\n", c);
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

#define all(c) (c).begin(), (c).end()

using namespace std;

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

int dp[(1 << 10)][1002];

int main(void) {

  dp[0][0] = 1;
  for (int S = 0; S < (1 << 10); S++) {
    for (int i = 0; i < 10; i++) {
      if (!(S >> i & 1)) {
        for (int s = 0; s < 1000; s++) {
          if ((count(S) + 1) * i + s < 1000)
            dp[S | (1 << i)][(count(S) + 1) * i + s] += dp[S][s];
        }
      }
    }
  }

  int n, s;

  while (cin >> n >> s) {

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

    int ans = 0;
    for (int i = 0; i < (1 << 10); i++)
      if (count(i) == n)
        ans += dp[i][s];

    cout << ans << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

#define all(c) (c).begin(), (c).end()

using namespace std;

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

// int dp[(1<<10)][1002];

int main(void) {
  /*
  dp[0][0]=1;
  for(int S=0;S<(1<<10);S++){
    for(int i=0;i<10;i++){
      if(!(S>>i&1)){
        for(int s=0;s<1000;s++){
          if((count(S)+1)*i+s<1000)
          dp[S|(1<<i)][(count(S)+1)*i+s]+=dp[S][s];
        }
      }
    }
  }
  */
  int n, s;

  while (cin >> n >> s) {
    assert(s < 1000);
    int ans = 0;
    // for(int i=0;i<(1<<10);i++)
    // if(count(i)==n)ans+=dp[i][s];

    cout << ans << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int ans[15][1 << 11];

int n, s;
int dfs(int sum, int B, int depth) {
  ans[depth][sum]++;
  int bit_cnt = 0;
  int num = 0;
  for (int i = 0; i < 10; i++) {
    if (B & (1 << i))
      continue;
    num += dfs(sum + (depth + 1) * i, B + (1 << i), depth + 1);
  }
  return num;
}
int main() {

  dfs(0, 0, 0);
  while (cin >> n >> s) {
    cout << ans[n][s] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int memo[1000][1 << 11];

int n, s;
int dfs(int sum, int B, int depth) {
  if (depth == n) {
    if (sum == s) {
      /*for(int i = 9;i >= 0;i--)cout<<!!(B&(1<<i));
      cout<<endl;
      cout<<"*"<<endl;*/
    }
    return sum == s;
  }
  if (memo[depth][B]) {
    return 0; // memo[depth][B];
  }
  int bit_cnt = 0;
  int num = 0;
  for (int i = 0; i < 10; i++) {
    if (B & (1 << i))
      continue;
    num += dfs(sum + (depth + 1) * i, B + (1 << i), depth + 1);
  }
  memo[depth][B] = num;
  // cout<<"///"<<depth<<" "<<num<<endl;
  return num;
}
int main() {

  while (cin >> n >> s) {
    for (int i = 0; i < 15; i++)
      for (int j = 0; j < (1 << 11); j++)
        memo[i][j] = 0;
    cout << dfs(0, 0, 0) << endl;
  }

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

#include <stdio.h>
#include <string.h>
int a[11][331];
bool e[10];
void m(int d, int s) {
  for (int i = 0; i < 10; i++) {
    if (e[i])
      continue;
    a[d][s + d * i]++;
    if (d < 10) {
      e[i] = true;
      m(d + 1, s + d * i);
      e[i] = false;
    }
  }
}
int main(void) {
  memset(a, 0, sizeof(a));
  memset(e, 0, sizeof(e));
  m(1, 0);
  int n, s;
  while (~scanf("%d%d", &n, &s)) {
    if (n < 0 || n > 10 || s < 0 || s > 330)
      puts("0");
    else
      printf("%d\\n", a[n][s]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>
int a[10][331];
bool e[10];
void m(int d, int s) {
  for (int i = 0; i < 10; i++) {
    if (e[i])
      continue;
    a[d][s + d * i]++;
    if (d < 10) {
      e[i] = true;
      m(d + 1, s + d * i);
      e[i] = false;
    }
  }
}
int main(void) {
  memset(a, 0, sizeof(a));
  memset(e, 0, sizeof(e));
  m(1, 0);
  int n, s;
  while (~scanf("%d%d", &n, &s)) {
    if (n < 0 || n > 10 || s < 0 || s > 330)
      puts("0");
    else
      printf("%d\\n", a[n][s]);
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>

#define mp(x, y) make_pair(x, y)
#define ALL(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define each(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)

using namespace std;

typedef long long LINT;

const LINT MAX = 10;

int N, S;
map<int, LINT> d[1 << MAX][MAX];
map<int, int> ans[MAX + 1];

int bit(int n) {
  int res = 0;
  for (int i = 0; i < MAX; ++i) {
    if (n & (1 << i)) {
      ++res;
    }
  }
  return res;
}

int main(void) {
  for (int i = 0; i < MAX; ++i) {
    int state = 1 << i;
    d[state][i].insert(mp(i, 1));
    ans[1][i] = 1;
  }
  for (int state = 1, I = 1 << MAX; state < I; ++state) {
    int b = bit(state);
    for (int i = 0; i < MAX; ++i) {
      if (!(state & (1 << i))) {
        int next = state | (1 << i);
        for (int j = 0; j < MAX; ++j) {
          if (state & (1 << j)) {
            each(d[state][j], p) {
              LINT num = i * (b + 1) + (*p).first;
              d[next][i][num] += (*p).second;
              ans[b + 1][num] += (*p).second;
            }
          }
        }
      }
    }
  }
  while (cin >> N >> S) {
    int out;
    if (N > 10 || S > 330) {
      out = 0;
    } else {
      out = ans[N][S];
    }
    cout << out << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>

#define mp(x, y) make_pair(x, y)
#define ALL(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define each(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)

using namespace std;

typedef long long LINT;

const LINT MAX = 10;

int N, S;
map<int, LINT> d[1 << MAX][MAX];

int bit(int n) {
  int res = 0;
  for (int i = 0; i < MAX; ++i) {
    if (n & (1 << i)) {
      ++res;
    }
  }
  return res;
}

int main(void) {
  while (cin >> N >> S) {
    int ans = 0;
    for (int i = 0; i < MAX; ++i) {
      int state = 1 << i;
      d[state][i].insert(mp(i, 1));
    }
    for (int state = 1, I = 1 << MAX; state < I; ++state) {
      int b = bit(state);
      for (int i = 0; i < MAX; ++i) {
        if (!(state & (1 << i))) {
          int next = state | (1 << i);
          for (int j = 0; j < MAX; ++j) {
            if (state & (1 << j)) {
              each(d[state][j], p) {
                LINT num = i * (b + 1) + (*p).first;
                d[next][i][num] += (*p).second;
              }
            }
          }
        }
      }
      if (b == N) {
        for (int i = 0; i < MAX; ++i) {
          ans += d[state][i][S];
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <iostream>
using namespace std;
int dp[11][1024][341];
int main() {
  dp[0][0][0] = 1;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 1024; j++) {
      for (int k = 0; k < 331; k++) {
        if (dp[i][j][k] == 0)
          continue;
        for (int l = 0; l < 10; l++) {
          if (!((j >> l) & 1)) {
            dp[i + 1][j | (1 << l)][(i + 1) * l + k] += dp[i][j][k];
          }
        }
      }
    }
  }
  int n, s;
  while (cin >> n >> s) {
    int sum = 0;
    if (n > 10 || s > 330) {
      cout << 0 << endl;
      continue;
    }
    for (int i = 0; i < 1024; i++) {
      sum += dp[n][i][s];
    }
    cout << sum << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
using namespace std;
int dp[11][1024][341];
int main() {
  dp[0][0][0] = 1;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 1024; j++) {
      for (int k = 0; k < 331; k++) {
        if (dp[i][j][k] == 0)
          continue;
        for (int l = 0; l < 10; l++) {
          if (!((j >> l) & 1)) {
            dp[i + 1][j | (1 << l)][(i + 1) * l + k] += dp[i][j][k];
          }
        }
      }
    }
  }
  int n, s;
  while (cin >> n >> s) {
    int sum = 0;
    for (int i = 0; i < 1024; i++) {
      sum += dp[n][i][s];
    }
    cout << sum << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int ans[12][1024];

void dfs(int bit, int d, int s) {
  ans[d][s]++;
  for (int i = 0; i < 10; i++) {
    if (bit & (1 << i))
      dfs(bit - (1 << i), d + 1, s + (i * (d + 1)));
  }
}

int main() {
  int n, s;
  dfs((1 << 10) - 1, 0, 0);
  while (cin >> n >> s)
    cout << (s > 1023 ? 0 : ans[n][s]) << endl;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int n, s;
long long int ans = 0;

void dfs(int ss, int bit, int k) {
  if (ss >= s)
    return;
  if (k == n) {
    if (ss == s)
      ans++;
  } else {
    int sk = (s - ss) / (k + 1);
    for (int i = 0; i <= min(9, sk); i++) {
      if (!((bit >> i) & 1)) {
        dfs(ss + i * (k + 1), bit | 1 << i, k + 1);
      }
    }
  }
}

int main(void) {
  while (cin >> n >> s) {
    ans = 0;
    if (n > 10)
      cout << "0" << endl;
    else {
      for (int i = 0; i <= 9; i++) {
        dfs(i, 1 << i, 1);
      }
      cout << ans << endl;
    }
  }
  return 0;
}