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

#include <bits/stdc++.h>

using namespace std;

template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
                             const Iterator last) {
  if ((first == last) || (first == k) || (last == k))
    return false;
  Iterator itr1 = first;
  Iterator itr2 = last;
  ++itr1;
  if (last == itr1)
    return false;
  itr1 = last;
  --itr1;
  itr1 = k;
  --itr2;
  while (first != itr1) {
    if (*--itr1 < *itr2) {
      Iterator j = k;
      while (!(*itr1 < *j))
        ++j;
      std::iter_swap(itr1, j);
      ++itr1;
      ++j;
      itr2 = k;
      std::rotate(itr1, j, last);
      while (last != j) {
        ++j;
        ++itr2;
      }
      std::rotate(k, itr2, last);
      return true;
    }
  }
  std::rotate(first, k, last);
  return false;
}

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

  int n, s;
  while (cin >> n >> s) {
    int ret = 0;
    do {
      int sum = 0;
      for (int j = 0; j < n; j++)
        sum += v[j] * (j + 1);
      if (sum < s)
        continue;
      else if (sum == s) {
        ret++;
        continue;
      }
      vector<int> vv;
      for (int i = 0; i < n; i++)
        vv.push_back(v[i]);
      do {
        int sum = 0;
        for (int j = 0; j < n; j++)
          sum += vv[j] * (j + 1);
        if (sum == s)
          ret++;
      } while (next_permutation(vv.begin(), vv.end()));
    } while (next_combination(v.begin(), v.begin() + n, v.end()));
    cout << ret << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k,
                             const Iterator last) {
  if ((first == last) || (first == k) || (last == k))
    return false;
  Iterator itr1 = first;
  Iterator itr2 = last;
  ++itr1;
  if (last == itr1)
    return false;
  itr1 = last;
  --itr1;
  itr1 = k;
  --itr2;
  while (first != itr1) {
    if (*--itr1 < *itr2) {
      Iterator j = k;
      while (!(*itr1 < *j))
        ++j;
      std::iter_swap(itr1, j);
      ++itr1;
      ++j;
      itr2 = k;
      std::rotate(itr1, j, last);
      while (last != j) {
        ++j;
        ++itr2;
      }
      std::rotate(k, itr2, last);
      return true;
    }
  }
  std::rotate(first, k, last);
  return false;
}

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

  int n, s;
  while (cin >> n >> s) {
    int ret = 0;
    do {
      int sum = 0;
      for (int j = 0; j < n; j++)
        sum += v[j] * (j + 1);
      if (sum < s)
        continue;
      vector<int> vv;
      for (int i = 0; i < n; i++)
        vv.push_back(v[i]);
      do {
        int sum = 0;
        for (int j = 0; j < n; j++)
          sum += vv[j] * (j + 1);
        if (sum == s)
          ret++;
      } while (next_permutation(vv.begin(), vv.end()));
    } while (next_combination(v.begin(), v.begin() + n, v.end()));
    cout << ret << endl;
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define reep(i, f, n) for (int i = f; i < int(n); ++i)
#define rep(i, n) reep(i, 0, n)

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

int main() {
  vector<map<int, int>> ans(11);
  rep(i, 11) {
    int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    do {
      int sum = 0;
      rep(j, i) sum += a[j] * (j + 1);
      if (ans[i].count(sum))
        ans[i][sum]++;
      else
        ans[i][sum] = 1;
      reverse(a + i, a + 10);
    } while (next_permutation(a, a + 10));
  }

  int n, s;
  while (scanf("%d%d", &n, &s) != EOF) {
    if (n < 0 || 10 < n)
      puts("0");
    else
      printf("%d\\n", ans[n].count(s) ? ans[n][s] : 0);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define reep(i, f, n) for (int i = f; i < int(n); ++i)
#define rep(i, n) reep(i, 0, n)

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

int main() {
  int n, s;
  while (scanf("%d%d", &n, &s) != EOF) {
    if (n > 10) {
      puts("0");
      continue;
    }
    int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    int cnt = 0;
    do {
      int sum = 0;
      rep(i, n) sum += a[i] * (i + 1);
      cnt += sum == s;
      reverse(a + n, a + 10);
    } while (next_permutation(a, a + 10));
    printf("%d\\n", cnt);
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int dp[1 << 10][15000];
int main() {
  int n, s;
  while (~scanf("%d%d", &n, &s)) {
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    int ans = 0;
    rep(i, 1 << 10) {
      rep(j, s + 1) {
        if (!dp[i][j])
          continue;
        int cnt = 0;
        rep(k, 10) {
          if ((i >> k) & 1)
            cnt++;
        }
        if (cnt == n) {
          if (j == s)
            ans += dp[i][j];
          continue;
        }
        rep(k, 10) {
          if (!((i >> k) & 1)) {
            dp[i | (1 << k)][j + k * (cnt + 1)] += dp[i][j];
          }
        }
      }
    }
    printf("%d\\n", ans);
  }
}

Error: TLE

Fixed submission:

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

int n, s, cnt;
bool used[10];
void dfs(int size, int sum) {
  if (size == n) {
    if (sum == s)
      cnt++;
    return;
  }
  rep(i, 10) {
    if (!used[i]) {
      used[i] = true;
      dfs(size + 1, sum + (size + 1) * i);
      used[i] = false;
    }
  }
}
int main() {
  while (~scanf("%d%d", &n, &s)) {
    cnt = 0;
    memset(used, 0, sizeof(used));
    dfs(0, 0);
    printf("%d\\n", cnt);
  }
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>

using namespace std;

int n, s;
int dp[11][340][1 << 11];

int dfs(int idx, int sum, int bit) {
  int res = 0;

  if (dp[idx][sum][bit] >= 0)
    return dp[idx][sum][bit];

  if (idx == n) {
    if (sum == s)
      return 1;
    else
      return 0;
  }

  for (int u = 0; u < 10; u++) {
    if (!(bit >> u & 1)) {
      if (sum + (idx + 1) * u <= s)
        res += dfs(idx + 1, sum + (idx + 1) * u, (bit | 1 << u));
    }
  }

  return dp[idx][sum][bit] = res;
}

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

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int n, s;

int dfs(int idx, int sum, int bit) {
  int res = 0;

  if (idx == n) {
    if (sum == s)
      return 1;
    else
      return 0;
  }

  for (int u = 0; u < 10; u++) {
    if (!(bit >> u & 1)) {
      if (sum + (idx + 1) * u <= s)
        res += dfs(idx + 1, sum + (idx + 1) * u, (bit | 1 << u));
    }
  }

  return res;
}

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

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

// AOJ 0070 Combination of Number Sequences

#include <iostream>

using namespace std;

void set_count(int n, int sum, int used);

const int MAX_N = 10;
const int MAX_SUM = 330;

int count_s[MAX_N + 1][MAX_SUM + 1];

int main() {
  int n, s;

  set_count(1, 0, 0);

  while (cin) {
    cin >> n >> s;
    if (cin.eof())
      break;

    if (1 <= n && n <= 10 && 0 <= s && s <= 330)
      cout << count_s[n][s] << endl;
    else
      cout << 0 << endl;
  }

  return 0;
}

void set_count(int depth, int sum, int used) {
  int new_sum;
  int i, used_i;

  for (i = 0; i < 10; i++) {
    used_i = 1 << i;
    if (used & used_i)
      continue;

    new_sum = sum + depth * i;
    count_s[depth][new_sum] += 1;

    if (depth < MAX_N)
      set_count(depth + 1, new_sum, used | used_i);
  }
}

Error: 0

Fixed submission:

// AOJ 0070 Combination of Number Sequences

#include <iostream>

using namespace std;

void set_count(int n, int sum, int used);

const int MAX_N = 10;
const int MAX_SUM = 330;

int count_s[MAX_N + 1][MAX_SUM + 1];

int main() {
  int n, s;

  set_count(1, 0, 0);

  while (cin) {
    cin >> n >> s;
    if (cin.eof())
      break;

    cout << count_s[n][s] << endl;
  }

  return 0;
}

void set_count(int depth, int sum, int used) {
  int new_sum;
  int i, used_i;

  for (i = 0; i < 10; i++) {
    used_i = 1 << i;
    if (used & used_i)
      continue;

    new_sum = sum + depth * i;
    count_s[depth][new_sum] += 1;

    if (depth < MAX_N)
      set_count(depth + 1, new_sum, used | used_i);
  }
}
Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

using namespace std;

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

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

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

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int table[10 + 1][330 + 1];
int memo[10];

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

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

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

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

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

#include <cstring>
#include <iostream>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

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

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

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

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int table[10 + 1][330 + 2];
int memo[10];

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

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

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

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

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

#include <cstring>
#include <iostream>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

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

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

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

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

int table[10 + 1][9000];
int memo[10];

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

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

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

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

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

#include <cstring>
#include <iostream>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

int table[10 + 1][9700];
int memo[10];

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

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

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

int table[10 + 1][9600];
int memo[10];

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

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

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

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

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

#include <cstring>
#include <iostream>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

int table[10 + 1][9699];
int memo[10];

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

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

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

int table[10 + 1][9690];
int memo[10];

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

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

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

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

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

#include <cstring>
#include <iostream>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

int table[10 + 1][9697];
int memo[10];

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

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

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

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

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

int table[10 + 1][9696];
int memo[10];

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

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

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

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

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

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

const int MaxSum = 330;
const int MaxN = 10;
int table[MaxN + 1][MaxSum + 1];
int mask = (1 << MaxN) - 1;

void recur(int n, int depth, int sum) {
  if (depth == n) {
    ++table[n][sum];
  } else {
    for (int i = 0; i < MaxN; ++i) {
      int f = 1 << i;
      if (mask & f) {
        mask ^= f;
        recur(n, depth + 1, sum + (depth + 1) * i);
        mask ^= f;
      }
    }
  }
}

int main() {
  for (int i = 1; i <= MaxN; ++i)
    recur(i, 0, 0);

  int n, s;
  while (scanf("%d %d", &n, &s) != EOF) {
    if (s <= MaxSum)
      printf("%d\\n", table[n][s]);
    else
      puts("0");
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void p(int *a, int n) {
  for (int i = 0; i < n; ++i)
    printf("%d ", a[i]);
  printf("\\n");
}
int main() {
  int n, s;
  while (scanf("%d %d\\n", &n, &s) != EOF) {
    int res = 0;

    int combi[10];
    int f = (1 << n) - 1;
    do {
      for (int i = 0, j = 0; j < n; ++i) {
        if (f & (1 << i))
          combi[j++] = i;
      }

      sort(combi, combi + n, greater<int>());
      do {
        int ts = 0;
        for (int i = 0; i < n; ++i)
          ts += (i + 1) * combi[i];

        if (ts == s)
          ++res;
        else if (ts > s)
          break;
      } while (next_permutation(combi, combi + n, greater<int>()));

      // combination
      int leastBit = f & -f;
      int mostBits = f + leastBit;
      int leastSequentialBits = f & ~mostBits;
      f = mostBits | ((leastSequentialBits / leastBit) >> 1);
    } while (f < 1 << 10);

    printf("%d\\n", res);
  }

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

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>   // require fabs
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime>   // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int n, s;
bool used[10];
ll total[12][10000];

void dfs(int curr, int sum) {
  if (curr == n) {
    total[n][sum]++;
    return;
  } // end if

  int res = 0;
  rep(i, 10) {
    if (!used[i]) {
      used[i] = true;
      dfs(curr + 1, sum + (curr + 1) * i);
      used[i] = false;
    } // end if
  }   // end rep
}

int main() {
  //	cut here before submit
  //	freopen ("testcase.CNS", "r", stdin );
  memset(total, 0, sizeof(total));

  for (n = 1; n <= 10; n++) {
    memset(used, 0, sizeof(used));
    dfs(0, 0);
  } // end for

  while (scanf("%d %d", &n, &s) != EOF) {
    printf("%d\\n", total[n][s]);
  } // end loop

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>   // require fabs
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit atof atoi
#include <cstring> // require memset
#include <ctime>   // require srand
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int n, s;
bool used[10];
ll total[12][1000];

void dfs(int curr, int sum) {
  if (curr == n) {
    total[n][sum]++;
    return;
  } // end if

  int res = 0;
  rep(i, 10) {
    if (!used[i]) {
      used[i] = true;
      dfs(curr + 1, sum + (curr + 1) * i);
      used[i] = false;
    } // end if
  }   // end rep
}

int main() {
  //	cut here before submit
  //	freopen ("testcase.CNS", "r", stdin );
  memset(total, 0, sizeof(total));

  for (n = 1; n <= 10; n++) {
    memset(used, 0, sizeof(used));
    dfs(0, 0);
  } // end for

  while (scanf("%d %d", &n, &s) != EOF) {
    printf("%d\\n", total[n][s]);
  } // end loop

  return 0;
}