prithivMLmods/Coder-Stat huggingface dataset:
Problem p00069 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int n, m, h, d;
vector<string> F;

bool judge(vector<string> f) {
  int now = m;
  for (int i = 0; i < f.size(); i++) {
    assert(now != 0);
    if (f[i][now - 1] == '1') {
      now = now - 1;
    } else if (f[i][now] == '1') {
      now = now + 1;
    }
    // cout<<F[i]<<" "<<f[i]<<" "<<now<<endl;
  }
  return now == h;
}

pair<int, int> solve() {
  if (judge(F))
    return make_pair(0, 0);
  for (int i = 0; i < F.size(); i++) {
    for (int j = 1; j < F.size() - 1; j++) {
      vector<string> tmp = F;
      if (tmp[i][j - 1] != '1' && tmp[i][j + 1] != '1') {
        tmp[i][j] = '1';
        if (judge(tmp)) {
          return make_pair(i + 1, j);
        }
      }
    }
  }
  return make_pair(-1, 0);
}

int main() {
  while (cin >> n, n != 0) {
    cin >> m >> h >> d;
    F.clear();
    for (int i = 0; i < d; i++) {
      string s;
      cin >> s;
      s = "*" + s + "*";
      F.push_back(s);
    }
    pair<int, int> ans = solve();
    if (ans.first == 0) {
      cout << 0 << endl;
    } else if (ans.first == -1) {
      cout << 1 << endl;
    } else {
      cout << ans.first << " " << ans.second << endl;
    }
  }
}

Fixed submission:
#include <cassert>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int n, m, h, d;
vector<string> F;

bool judge(vector<string> f) {
  int now = m;
  for (int i = 0; i < f.size(); i++) {
    assert(now != 0);
    if (f[i][now - 1] == '1') {
      now = now - 1;
    } else if (f[i][now] == '1') {
      now = now + 1;
    }
    // cout<<F[i]<<" "<<f[i]<<" "<<now<<endl;
  }
  return now == h;
}

pair<int, int> solve() {
  if (judge(F))
    return make_pair(0, 0);
  for (int i = 0; i < F.size(); i++) {
    for (int j = 1; j < F[i].size() - 1; j++) {
      vector<string> tmp = F;
      if (tmp[i][j - 1] != '1' && tmp[i][j + 1] != '1') {
        tmp[i][j] = '1';
        if (judge(tmp)) {
          return make_pair(i + 1, j);
        }
      }
    }
  }
  return make_pair(-1, 0);
}

int main() {
  while (cin >> n, n != 0) {
    cin >> m >> h >> d;
    F.clear();
    for (int i = 0; i < d; i++) {
      string s;
      cin >> s;
      s = "*" + s + "*";
      F.push_back(s);
    }
    pair<int, int> ans = solve();
    if (ans.first == 0) {
      cout << 0 << endl;
    } else if (ans.first == -1) {
      cout << 1 << endl;
    } else {
      cout << ans.first << " " << ans.second << endl;
    }
  }
}
Problem p00069 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

bool Simulation(char line[][15], int start, int goal, int m) {
  int pos = start;

  for (int i = 0; i < m; i++) {
    if (line[i][pos] == '1') {
      pos++;
    } else if (line[i][pos - 1] == '1') {
      pos--;
    }
  }
  return (pos == goal);
}

int main(void) {
  int n, m;
  int start;
  int goal;
  char line[30][15];

  while (1) {
    scanf("%d", &n);
    scanf("%d", &start);
    scanf("%d", &goal);
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
      scanf("%s", line[i] + 1);
      line[i][0] = '0';
      line[i][n] = '0';
    }

    if (Simulation(line, start, goal, m) == true) {
      puts("0");
      continue;
    }

    bool flag = false;
    for (int i = 0; i < m; i++) {
      for (int j = 1; j < n; j++) {
        if (line[i][j - 1] == '0' && line[i][j + 1] == '0' &&
            line[i][j] == '0') {
          line[i][j] = '1';
          if (Simulation(line, start, goal, m) == true) {
            printf("%d %d\n", i + 1, j);
            flag = true;
            break;
          }
          line[i][j] = '0';
        }
      }
      if (flag == true) {
        break;
      }
    }

    if (flag == false) {
      puts("1");
    }
  }

  return (0);
}

Fixed submission:
#include <stdio.h>

bool Simulation(char line[][15], int start, int goal, int m) {
  int pos = start;

  for (int i = 0; i < m; i++) {
    if (line[i][pos] == '1') {
      pos++;
    } else if (line[i][pos - 1] == '1') {
      pos--;
    }
  }
  return (pos == goal);
}

int main(void) {
  int n, m;
  int start;
  int goal;
  char line[30][15];

  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    scanf("%d", &start);
    scanf("%d", &goal);
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
      scanf("%s", line[i] + 1);
      line[i][0] = '0';
      line[i][n] = '0';
    }

    if (Simulation(line, start, goal, m) == true) {
      puts("0");
      continue;
    }

    bool flag = false;
    for (int i = 0; i < m; i++) {
      for (int j = 1; j < n; j++) {
        if (line[i][j - 1] == '0' && line[i][j + 1] == '0' &&
            line[i][j] == '0') {
          line[i][j] = '1';
          if (Simulation(line, start, goal, m) == true) {
            printf("%d %d\n", i + 1, j);
            flag = true;
            break;
          }
          line[i][j] = '0';
        }
      }
      if (flag == true) {
        break;
      }
    }

    if (flag == false) {
      puts("1");
    }
  }

  return (0);
}
Problem p00069 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int N, M, G, D;

bool c(vector<string> m) {
  int y = M - 1;
  for (int x = 0; x < D + 1; x++) {
    if (y < N - 1 && m[x][y] == '1') {
      y++;
    } else if (0 < y && m[x][y - 1] == '1') {
      y--;
    }
  }
  if (y == G - 1)
    return true;
  else
    return false;
}

bool t(string g) {
  for (int i = 0; i < g.size() - 1; i++) {
    if (g[i] == '1' && g[i + 1] == '1')
      return false;
  }
  return true;
}

int main() {
  while (cin >> N, N) {
    cin >> M >> G >> D;
    vector<string> v(D);
    for (int i = 0; i < D; i++) {
      cin >> v[i];
    }
    if (c(v)) {
      cout << 0 << endl;
      goto escape;
    }
    for (int i = 0; i < D; i++) {
      for (int j = 0; j < N - 1; j++) {
        if (v[i][j] != '1') {
          v[i][j] = '1';
          if (t(v[i])) {
            if (c(v)) {
              cout << i + 1 << " " << j + 1 << endl;
              goto escape;
            };
          }
          v[i][j] = '0';
        }
      }
    }
    cout << 1 << endl;
  escape:;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int N, M, G, D;

bool c(vector<string> m) {
  int y = M - 1;
  for (int x = 0; x < D; x++) {
    if (y < N - 1 && m[x][y] == '1') {
      y++;
    } else if (0 < y && m[x][y - 1] == '1') {
      y--;
    }
  }
  if (y == G - 1)
    return true;
  else
    return false;
}

bool t(string g) {
  for (int i = 0; i < g.size() - 1; i++) {
    if (g[i] == '1' && g[i + 1] == '1')
      return false;
  }
  return true;
}

int main() {
  while (cin >> N, N) {
    cin >> M >> G >> D;
    vector<string> v(D);
    for (int i = 0; i < D; i++) {
      cin >> v[i];
    }
    if (c(v)) {
      cout << 0 << endl;
      goto escape;
    }
    for (int i = 0; i < D; i++) {
      for (int j = 0; j < N - 1; j++) {
        if (v[i][j] != '1') {
          v[i][j] = '1';
          if (t(v[i])) {
            if (c(v)) {
              cout << i + 1 << " " << j + 1 << endl;
              goto escape;
            };
          }
          v[i][j] = '0';
        }
      }
    }
    cout << 1 << endl;
  escape:;
  }

  return 0;
}
Problem p00070 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

bool used[10];
int sum;
int dp[11][1000];
void saiki(int c, int d) { // c?????§??§d
  dp[c][d]++;
  if (c == 10) {
    return;
  }
  for (int e = 0; e < 10; e++) {
    if (!used[e]) {
      used[e] = true;
      saiki(c + 1, d + (c + 1) * e);
      used[e] = false;
    }
  }
}
int main() {
  saiki(0, 0);
  int a, b;
  while (cin >> a >> b) {
    cout << dp[a][b] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

bool used[10];
int sum;
int dp[11][10005];
void saiki(int c, int d) { // c?????§??§d
  dp[c][d]++;
  if (c == 10) {
    return;
  }
  for (int e = 0; e < 10; e++) {
    if (!used[e]) {
      used[e] = true;
      saiki(c + 1, d + (c + 1) * e);
      used[e] = false;
    }
  }
}
int main() {
  saiki(0, 0);
  int a, b;
  while (cin >> a >> b) {
    cout << dp[a][b] << endl;
  }
}
Problem p00070 (C++)

Buggy submission (status: 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][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;
}

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][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;
}
Problem p00070 (C++)

Buggy submission (status: 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++) {
        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();
}

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++)
        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();
}
Problem p00070 (C++)

Buggy submission (status: 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));
    cout << ans(n, (1 << 10) - 1, s) << endl;
  }
  return 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));
    if (s >= 1000 || n > 10)
      cout << 0 << endl;
    else
      cout << ans(n, (1 << 10) - 1, s) << endl;
  }
  return 0;
}
Problem p00070 (C++)

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

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

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

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

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

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

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

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

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1 && s < 10) {
    if (!(x & (1 << s))) {
      y = 1;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1) {
    if (s < 10 && !(x & (1 << s))) {
      y = 1;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}
Problem p00070 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1 && s < 10) {
    if (!(x & (1 << s))) {
      y = 1;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1) {
    if (s < 10) {
      if (!(x & (1 << s))) {
        y = 1;
      }
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}
Problem p00070 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (s < 10) {
    if (n == 1) {
      if (!(x & (1 << s))) {
        y = 1;
      }
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
int dp[11][1 << 10][331];
int ans(int n, int x, int s);
int main() {
  int n, m;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> m) {
    if (n > 10 || 330 < m) {
      cout << "0" << endl;
    } else {
      cout << ans(n, 0, m) << endl;
    }
  }
  return 0;
}
int ans(int n, int x, int s) {
  int y = 0;
  if (dp[n][x][s] >= 0) {
    return dp[n][x][s];
  }
  if (s < 0) {
    return 0;
  }
  if (n == 1) {
    if (s < 10) {
      if (!(x & (1 << s))) {
        y = 1;
      }
    }
  } else {
    for (int i = 0; i < 10; i++) {
      if (!(x & (1 << i))) {
        y += ans(n - 1, x | (1 << i), s - i * n);
      }
    }
  }
  dp[n][x][s] = y;
  return y;
}
Problem p00070 (C++)

Buggy submission (status: 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, n + s) {
    cout << dp[n - 1][s] / factorial(10 - n) << endl;
  }
  return 0;
}

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) {
    cout << dp[n - 1][s] / factorial(10 - n) << endl;
  }
  return 0;
}
Problem p00070 (C++)

Buggy submission (status: 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) {
    cout << results[n][s] << endl;
  }
  return 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) {
    if (s > S_MAX)
      cout << 0 << endl;
    else
      cout << results[n][s] << endl;
  }
  return 0;
}
Problem p00070 (C++)

Buggy submission (status: Runtime Error):
// 23
#include <iostream>
#include <map>

using namespace std;

int m[11][1000];

void calc(int p, int d, int u) {
  if (d <= 10) {
    for (int i = 0; i <= 9; i++) {
      if (!(u & 1 << i)) {
        int cs = p + i * d;
        m[d][cs]++;
        calc(cs, d + 1, u | 1 << i);
      }
    }
  }
}

int main() {
  calc(0, 1, 0);
  for (int n, s; cin >> n >> s;) {
    cout << m[n][s] << endl;
  }
  return 0;
}

Fixed submission:
// 23
#include <iostream>
#include <map>

using namespace std;

int m[11][1000];

void calc(int p, int d, int u) {
  if (d <= 10) {
    for (int i = 0; i <= 9; i++) {
      if (!(u & 1 << i)) {
        int cs = p + i * d;
        m[d][cs]++;
        calc(cs, d + 1, u | 1 << i);
      }
    }
  }
}

int main() {
  calc(0, 1, 0);
  for (int n, s; cin >> n >> s;) {
    cout << ((s < 1000) ? m[n][s] : 0) << endl;
  }
  return 0;
}
Problem p00070 (C++)

Buggy submission (status: 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;

  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;
}

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;
  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;
}
Problem p00070 (C++)

Buggy submission (status: 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 = 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;
  }
}

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 = 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;
  }
}
Problem p00070 (C++)

Buggy submission (status: 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) {
    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;
}

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) {
    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;
}
Problem p00070 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n, s;
int memo[100][1000][1 << 10];

int solve(int i, int j, int v) {
  if (memo[i][j][v] >= 0)
    return memo[i][j][v];
  if (i == n) {
    if (j == s)
      return 1;
    else
      return 0;
  }

  int res = 0;
  REP(k, 10) {
    if ((v >> k) & 1)
      continue;
    if (j + k * (i + 1) > s)
      break;
    res += solve(i + 1, j + (i + 1) * k, v | (1 << k));
  }
  return memo[i][j][v] = res;
}

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n, s;
int memo[11][800][1 << 10];

int solve(int i, int j, int v) {
  if (memo[i][j][v] >= 0)
    return memo[i][j][v];
  if (i == n) {
    if (j == s)
      return 1;
    else
      return 0;
  }

  int res = 0;
  REP(k, 10) {
    if ((v >> k) & 1)
      continue;
    if (j + k * (i + 1) > s)
      break;
    res += solve(i + 1, j + (i + 1) * k, v | (1 << k));
  }
  return memo[i][j][v] = res;
}

int main() {
  while (cin >> n >> s) {
    MS(memo, -1);
    cout << solve(0, 0, 0) << endl;
  }
  return 0;
}
Problem p00070 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n, s;
int dp[20][1000][1100];
int solve(int i, int sum, int used) {
  if (dp[i][sum][used] >= 0)
    return dp[i][sum][used];
  if (i == n + 1 && sum == s)
    return 1;
  if (i > n || sum > s)
    return 0;
  int res = 0;
  REP(j, 10) {
    if (((used >> j) & 1) == 0 && sum + i * j <= s) {
      res += solve(i + 1, sum + i * j, used | (1 << j));
    }
  }
  return dp[i][sum][used] = res;
}

int main() {
  while (cin >> n >> s) {
    MS(dp, -1);
    cout << solve(1, 0, 0) << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int n, s;
int dp[20][500][1100];
int solve(int i, int sum, int used) {
  if (dp[i][sum][used] >= 0)
    return dp[i][sum][used];
  if (i == n + 1 && sum == s)
    return 1;
  if (i > n || sum > s)
    return 0;
  int res = 0;
  REP(j, 10) {
    if (((used >> j) & 1) == 0 && sum + i * j <= s) {
      res += solve(i + 1, sum + i * j, used | (1 << j));
    }
  }
  return dp[i][sum][used] = res;
}

int main() {
  while (cin >> n >> s) {
    MS(dp, -1);
    cout << solve(1, 0, 0) << endl;
  }
  return 0;
}
Problem p00070 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int n, s, memo[1024][500];

int search(int stat, int sum, int dep) {
  if (dep == n)
    return memo[stat][sum] = (s == sum);
  // if(~memo[stat][sum])    return memo[stat][sum];
  if (sum > s)
    return 0;

  int cnt = 0;
  for (int i = 0; i < 10; i++) {
    if ((stat & (1 << i)) == 0) {
      stat |= 1 << i;
      cnt += search(stat, sum + i * (n - dep), dep + 1);
      stat &= ~(1 << i);
    }
  }
  return memo[stat][sum] = cnt;
}

int main() {
  while (cin >> n >> s) {
    if (n == 0 || s >= 1000) {
      puts("0");
      continue;
    }
    memset(memo, -1, sizeof(memo));
    cout << search(0, 0, 0) << endl;
  }

  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int n, s, memo[1024][500];

int search(int stat, int sum, int dep) {
  if (dep == n)
    return memo[stat][sum] = (s == sum);
  if (~memo[stat][sum])
    return memo[stat][sum];
  if (sum > s)
    return 0;

  int cnt = 0;
  for (int i = 0; i < 10; i++) {
    if ((stat & (1 << i)) == 0) {
      stat |= 1 << i;
      cnt += search(stat, sum + i * (n - dep), dep + 1);
      stat &= ~(1 << i);
    }
  }
  return memo[stat][sum] = cnt;
}

int main() {
  while (cin >> n >> s) {
    if (n == 0 || s >= 1000) {
      puts("0");
      continue;
    }
    memset(memo, -1, sizeof(memo));
    cout << search(0, 0, 0) << endl;
  }

  return 0;
}
Problem p00070 (C++)

Buggy submission (status: 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 || 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;
}

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 || 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;
}
Problem p00070 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p00070 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p00070 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p00070 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}