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

#include <iostream>
using namespace std;

#define MAX_N 50
#define MAX_M 101
#define MAX_S 5000

long long x[MAX_N][MAX_M][MAX_S + 1], y[MAX_N][MAX_S + 1];
int main() {
  x[0][0][0] = 1;
  x[1][0][0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    for (int j = 0; j < MAX_M; j++) {
      for (int k = 0; k <= MAX_S; k++) {
        if (x[i - 1][j][k] >= 1) {
          for (int l = j + 1; l < MAX_M; l++) {
            if (k + l > MAX_S) {
              goto E;
            }
            x[i][l][k + l] += x[i - 1][j][k];
          }
        E:;
        }
      }
    }
  }
  for (int i = 0; i < MAX_N; i++) {
    for (int j = 0; j < MAX_M; j++) {
      for (int k = 0; k <= MAX_S; k++) {
        y[i][k] += x[i][j][k];
      }
    }
  }
  int a, b;
  while (true) {
    cin >> a >> b;
    if (!a && !b) {
      break;
    }
    cout << y[a][b] << endl;
  }
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;

#define MAX_N 11
#define MAX_M 1050
#define MAX_S 1050

long long x[MAX_N][MAX_M][MAX_S + 1], y[MAX_N][MAX_S];
int main() {
  x[0][0][0] = 1;
  x[1][0][0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    for (int j = 0; j < MAX_M; j++) {
      for (int k = 0; k <= MAX_S; k++) {
        if (x[i - 1][j][k] >= 1) {
          for (int l = j + 1; l < MAX_M; l++) {
            if (k + l > MAX_S) {
              goto E;
            }
            x[i][l][k + l] += x[i - 1][j][k];
          }
        E:;
        }
      }
    }
  }
  for (int i = 0; i < MAX_N; i++) {
    for (int j = 0; j < MAX_M; j++) {
      for (int k = 0; k < MAX_S; k++) {
        y[i][k] += x[i][j][k];
      }
    }
  }
  int a, b;
  while (true) {
    cin >> a >> b;
    if (!a && !b) {
      break;
    }
    cout << y[a][b];
  }
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  const int MAX_NO = 100;
  const int MAX_NOS = 9;
  const int MAX_SUM = 1000;

  int n[51], s[51], c = 0;
  long long dp[MAX_NOS + 1][MAX_NO + 1][MAX_SUM + 1];

  long long SUM = 0;

  memset(dp, 0, sizeof(dp));

  for (int i = 0; i <= MAX_NO; i++) {
    dp[1][i][i] = 1;
  }

  for (int N = 2; N <= MAX_NOS; N++) {
    for (int i = 1; i <= MAX_NO; i++) {
      for (int j = 1; j <= MAX_SUM; j++) {
        if (j - i >= 0) {
          for (int k = 0; k < i; k++) {
            dp[N][i][j] += dp[N - 1][k][j - i];
          }
        }
      }
    }
  }

  while (true) {
    cin >> n[c] >> s[c];

    if (n[c] == 0 && s[c] == 0) {
      goto Exit;
    }

    c++;
  }

Exit:;

  for (int p = 0; p < c; p++) {
    SUM = 0;

    for (int i = 0; i <= MAX_NO; i++) {
      SUM += dp[n[p]][i][s[p]];
    }

    cout << SUM << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

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

using namespace std;

int main() {
  int n[50], s[50], c = 0, dp[101][101][901];

  long long SUM = 0;

  memset(dp, 0, sizeof(dp));

  for (int i = 0; i <= 100; i++) {
    dp[1][i][i] = 1;
  }

  for (int N = 2; N <= 100; N++) {
    for (int i = 1; i <= 100; i++) {
      for (int j = 1; j <= 900; j++) {
        if (j - i >= 0) {
          for (int k = 0; k < i; k++) {
            dp[N][i][j] += dp[N - 1][k][j - i];
          }
        }
      }
    }
  }

  while (true) {
    cin >> n[c] >> s[c];

    if (n[c] == 0 && s[c] == 0) {
      goto Exit;
    }

    c++;
  }

Exit:;

  for (int p = 0; p < c; p++) {
    SUM = 0;

    for (int i = 0; i < 100; i++) {
      SUM += dp[n[p]][i][s[p]];
    }

    cout << SUM << endl;
  }

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

#include <algorithm>
#include <cstring>
#include <iostream>

long long int dp[10][101][1001];
int n, s;
int maxs;
using namespace std;

long long int check(int i, int cnt, int sum) {
  if (sum == s && cnt == n) {
    //    cout<<i<<" "<<cnt<<" "<<sum<<endl;
    return 1;
  }
  if (sum >= s || cnt >= n || i >= 100)
    return 0;
  if (dp[cnt][i][sum] != -1)
    return dp[cnt][i][sum];
  long long int ans = 0;
  for (int j = i + 1; j <= maxs; j++)
    ans += check(j, cnt + 1, sum + j);

  dp[cnt][i][sum] = ans;
  return ans;
}
int main() {

  for (; cin >> n >> s, n;) {
    memset(dp, -1, sizeof(dp));
    long long int ans = 0;
    maxs = min(s, 100);
    for (int i = 0; i <= maxs; i++)
      ans += check(i, 1, i);

    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>

long long int dp[10][101][1001];
int n, s;
int maxs;
using namespace std;

long long int check(int i, int cnt, int sum) {
  if (sum == s && cnt == n) {
    //    cout<<i<<" "<<cnt<<" "<<sum<<endl;
    return 1;
  }
  if (sum >= s || cnt >= n || i >= 100)
    return 0;
  if (dp[i][cnt][sum] != -1)
    return dp[i][cnt][sum];
  long long int ans = 0;
  for (int j = i + 1; j <= maxs; j++)
    ans += check(j, cnt + 1, sum + j);

  dp[i][cnt][sum] = ans;
  return ans;
}
int main() {

  for (; cin >> n >> s, n;) {
    memset(dp, -1, sizeof(dp));
    long long int ans = 0;
    maxs = min(s, 100);
    for (int i = 0; i <= maxs; i++)
      ans += check(i, 1, i);

    cout << ans << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>

#define N 100
#define S 1000

using namespace std;

int main() {

  int n, s;
  long long int soi[10][S + 1] = {};

  soi[1][0] = 1;

  for (int i = 1; i <= N; i++) {
    for (int j = 8; j > 0; j--) {
      for (int k = 0; k <= S; k++) {
        if (soi[j][k] != 0) {
          soi[j + 1][k + i] += soi[j][k];
        }
      }
    }
    soi[1][i] = 1;
  }

  while (1) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;

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

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>

#define N 100
#define S 1000

using namespace std;

int main() {

  int n, s;
  long long int soi[N][S + 1] = {};

  soi[1][0] = 1;

  for (int i = 1; i <= N - 1; i++) {
    for (int j = i; j > 0; j--) {
      for (int k = 0; k <= S; k++) {
        if (soi[j][k] != 0) {
          soi[j + 1][k + i] += soi[j][k];
        }
      }
    }
    soi[1][i] = 1;
  }

  while (1) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;

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

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

#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
int m, num;
int mem[15][1005][1005] = {0};

long int lfor(int n, int sum, int mininum) {
  long int lsum = 0;
  if (mem[n][sum][mininum] != -1) {
    return mem[n][sum][mininum];
  }
  if (n == 0 && sum == 0) {
    return 1;
  }
  if (n == 0) {
    return 0;
  }
  for (int i = mininum; i <= 100; i++) {
    if (sum - i >= 0)
      lsum = lsum + lfor(n - 1, sum - i, i + 1);
  }
  mem[n][sum][mininum] = lsum;
  return lsum;
}

int main() {
  memset(mem, -1, sizeof(mem));
  long int ans;
  while (1) {
    ans = 0;
    scanf("%d %d", &m, &num);
    if (m == 0 && num == 0)
      break;
    ans = lfor(m, num, 0);
    printf("%lld\\n", ans);
  }
  return 0;
}

/*n/k

(n+k-1)/k*/

// fill_n(mem[0][0], 10 * 1002 * 1002, 114514);
// fill(**memo, **memo+sizeof(mem),
// fill((int*)mem, (int*)mem + 10 * 1002 * 1002, 114514);
// fill(mem[0][0], mem[10][0], 114514);

Error: MLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
int m, num;
int mem[25][2000][2000] = {0};

long int lfor(int n, int sum, int mininum) {
  long int lsum = 0;
  // printf("%d %d %d\\n",n,sum,mininum);
  if (mem[n][sum][mininum] != -1) {
    return mem[n][sum][mininum];
  }
  if (n == 0 && sum == 0) {

    return 1;
  }
  if (n == 0) {
    return 0;
  }
  for (int i = mininum; i <= 100; i++) {
    lsum = lsum + lfor(n - 1, sum - i, i + 1);
  }
  mem[n][sum][mininum] = lsum;
  return lsum;
}

int main() {
  memset(mem, -1, sizeof(mem));
  long int ans;
  while (scanf("%d", &m) != -1) {
    ans = 0;
    scanf("%d", &num);
    ans = lfor(m, num, 0);
    printf("%lld\\n", ans);
  }
  return 0;
}

/*n/k

(n+k-1)/k*/

// fill_n(mem[0][0], 10 * 1002 * 1002, 114514);
// fill(**memo, **memo+sizeof(mem),
// fill((int*)mem, (int*)mem + 10 * 1002 * 1002, 114514);
// fill(mem[0][0], mem[10][0], 114514);
Problem p00097 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long comb(int, int, int);
int purp;
long long memo[1001][101][11];

int main() {
  int total, n;
  while (cin >> n >> total, n || total) {
    for (int i = 0; i < 1001; ++i)
      for (int j = 0; j < 101; ++j)
        for (int k = 0; k < 11; ++k)
          memo[i][j][k] = -1;
    purp = total;
    cout << comb(0, 0, n) << endl;
  }
  return 0;
}

long long comb(int sum, int min, int n) {
  if (memo[sum][min][n] != -1)
    return memo[sum][min][n];
  if (n == 0 && sum == purp)
    return 1;
  if (sum > purp || n < 0)
    return 0;
  long long res = 0;
  for (int i = min; i <= 100; ++i) {
    res += comb(sum + i, i + 1, n - 1);
  }
  memo[sum][min][n] = res;
  return res;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int comb(int, int, int);
int purp;
int memo[1001][1001][101];

int main() {
  int total, n;
  while (cin >> n >> total, n || total) {
    for (int i = 0; i < 1001; ++i)
      for (int j = 0; j < 1001; ++j)
        for (int k = 0; k < 101; ++k)
          memo[i][j][k] = -1;
    purp = total;
    cout << comb(0, 0, n) << endl;
  }
  return 0;
}

int comb(int sum, int min, int n) {
  if (memo[sum][min][n] != -1)
    return memo[sum][min][n];
  if (n == 0 && sum == purp)
    return 1;
  if (sum > purp || n < 0)
    return 0;
  int res = 0;
  for (int i = min; i <= 100; ++i) {
    res += comb(sum + i, i + 1, n - 1);
  }
  memo[sum][min][n] = res;
  return res;
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <cmath>
#include <ctype.h>
#include <exception>
#include <fstream>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#define NN 100
#define SS 1000

using namespace std;
typedef long long int lint;

lint dp[NN + 1][10][SS + 1] = {0};

bool AOJ0097() {
  int n, s;
  cin >> n >> s;
  if (n == 0)
    return false;

  lint sum = 0;
  for (int x = 0; x <= NN; x++) {
    sum += dp[x][n][s];
  }
  cout << sum << endl;

  return true;
}

int main() {

  dp[0][0][0] = 1;
  for (int x = 0; x <= NN; x++) {
    dp[x][1][x] = 1;
  }
  for (int n = 2; n < 10; n++) {
    for (int x = 0; x <= NN; x++) {
      for (int s = x; s <= SS; s++) {
        for (int i = 1; i <= x; i++) {
          dp[x][n][s] += dp[x - i][n - 1][s - x];
        }
      }
    }
  }

  while (AOJ0097()) {
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>

using namespace std;
typedef long long int lint;

lint dp[10][100][1000] = {0};

lint rec(lint n, lint x, lint s) {
  if (dp[n][x][s] != -1)
    return dp[n][x][s];

  lint ret = 0;
  for (lint k = 1; (x >= k && s >= k * n - 1); k++) {
    ret += rec(n - 1, x - k, s - k * n + 1);
  }

  return (dp[n][x][s] = ret);
}

void answer() {
  lint n, x, s;
  for (n = 0; n < 10; n++) {
    for (x = 0; x <= 100; x++) {
      for (s = 0; s <= 1000; s++) {
        dp[n][x][s] = -1;
      }
    }
  }
  for (x = 0; x <= 100; x++) {
    dp[0][x][0] = 1;
    for (s = 1; s <= 1000; s++) {
      dp[0][x][s] = 0;
    }
  }

  while (1) {
    scanf("%lld %lld", &n, &s);
    if (n == 0 && s == 0)
      break;
    cout << rec(n, 100, s) << endl;
  }
}

int main() {
  answer();
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
typedef long long int Int;
const int MAX_N = 10;
const int MAX_NUM = 101;
const int MAX_S = 1001;

// do[何個使うか][いくつまで使ったか+1][合計いくつか]
Int N, S, dp[MAX_N][MAX_NUM + 5][MAX_S];

int main() {
  REP(i, MAX_N) REP(j, MAX_NUM) REP(k, MAX_S) dp[i][j][k] = 0;
  dp[0][0][0] = 1;
  REP(i, MAX_N - 1)
  REP(j, MAX_NUM)
  REP(k, MAX_S)
  FOR(l, j, MAX_NUM) {
    if (k + l > MAX_S)
      break;
    dp[i + 1][l + 1][k + l] += dp[i][j][k];
  }
  while (cin >> N >> S && N) {
    Int ans = 0;
    REP(i, MAX_NUM + 5) ans += dp[N][i][S];
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int N, S;

int dfs(int now, int sum, int cnt) {
  if (cnt == N && sum == S)
    return 1;
  if (cnt == N)
    return 0;
  if (sum + (N - cnt) * 100 < S)
    return 0;
  int res = 0;
  for (int i = now; i <= 100 && sum + i <= S; ++i)
    res += dfs(i + 1, sum + i, cnt + 1);
  return res;
}

int main() {
  while (cin >> N >> S && N)
    cout << dfs(0, 0, 0) << endl;
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll dp[10][1001]; //?????£????????°,???

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

Error: TLE

Fixed submission:

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

ll cnt;
int n, s;

void solve(int rest, int left, int sum) {
  if (!rest) {
    if (sum == s)
      cnt++;
    return;
  }
  for (int i = left + 1; i <= 100; i++) {
    solve(rest - 1, i, sum + i);
  }
}
int main() {
  while (cin >> n >> s, n) {
    cnt = 0;
    solve(n, -1, 0);
    cout << cnt << endl;
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  long dp[11][1001];
  int n, s;
  dp[0][0] = 1;
  for (int i = 0; i < 101; ++i) {
    for (int j = 9; j >= 0; --j) {
      for (int k = 0; k < 1001 - i; ++k)
        dp[j + 1][i + k] += dp[j][k];
    }
  }
  while (cin >> n >> s && n || s)
    cout << dp[n][s] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
long a;
int f(int n, int s, int i) {
  if (n == 1 && i >= s && s >= 0) {
    a++;
    return 0;
  }
  if (s <= 0 || s >= i * n)
    return 0;
  for (int j = i; j >= n - 1; j--)
    f(n - 1, s - j, j - 1);
}
int main() {
  int n, s;
  while (cin >> n >> s) {
    a = 0;
    if (n == 0 && s == 0)
      break;
    f(n, s, 100);
    cout << a << endl;
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#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;

#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value))
template <typename T> void FILL_(void *ptr, size_t size, T value) {
  std::fill((T *)ptr, (T *)ptr + size, value);
}
// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int n; // 使う個数
int s; // 求める和
int ans;

long long int dp[10][1010]; // dp[n][s]sをn個の整数で表すときの組み合わせ

int main() {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i < 101; i++) {
    for (int j = 1000; j > -1; j--) {
      for (int k = 9; k > 0; k--) {
        if (j - i >= 0) {
          dp[k][j] += dp[k - 1][j - i];
        }
      }
    }
  }
  while (cin >> n >> s, n || s) {
    cout << dp[n][s] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ctype.h>
#include <fstream>
#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;

#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr) / sizeof(value), (value))
template <typename T> void FILL_(void *ptr, size_t size, T value) {
  std::fill((T *)ptr, (T *)ptr + size, value);
}
// 4方向ベクトル→↑←↓
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int n; // 使う個数
int s; // 求める和
int ans;
void dfs(int sum, int i, int j) {
  if (sum > s) {
    return;
  }
  if (sum == s && j == 0) {
    ans++;
    return;
  }
  if (j == 0 || i == 100) {
    return;
  }
  dfs(sum + i, i + 1, j - 1); // 足す
  dfs(sum, i + 1, j);         // 足さない
}
int main() {
  while (cin >> n >> s) {
    if (s == 0) {
      cout << 0 << endl;
      continue;
    }
    ans = 0;
    dfs(0, 0, n);
    cout << ans << endl;
  }

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

#include <iostream>

using namespace std;

int main(void) {
  static long long n, s, dp[102][11][1001];

  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k < 1001; k++)
        dp[i][j][k] = 0;

  dp[0][0][0] = 1;

  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 1001; k++) {
        if (dp[i][j][k] == 0)
          continue;

        dp[i + 1][j][k] += dp[i][j][k];

        if (8 < j || 1000 < k + i)
          continue;

        dp[i + 1][j + 1][k + i] += dp[i][j][k];
      }
    }
  }

  while (cin >> n >> s, n | s)
    cout << dp[101][n][s] << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {
  long long n, s, dp[102][11][1001];

  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k < 1001; k++)
        dp[i][j][k] = 0;

  dp[0][0][0] = 1;

  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 1001; k++) {
        if (dp[i][j][k] == 0)
          continue;

        dp[i + 1][j][k] += dp[i][j][k];

        if (8 < j || 1000 < k + i)
          continue;

        dp[i + 1][j + 1][k + i] += dp[i][j][k];
      }
    }
  }

  while (cin >> n >> s, n | s)
    cout << dp[101][n][s] << endl;
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstring>
#include <iostream>

long long dp[11][1010];
int main() {
  int n, s;
  while (std::cin >> n >> s, n != 0 || s != 0) {
    memset(dp, 0, sizeof(dp));

    dp[0][0] = 1;

    for (int j = 0; j <= 100; ++j) {
      for (int k = 1010; k >= 0; --k) {
        for (int i = n; i >= 1; --i) {
          if (k - j < 0)
            continue;

          dp[i][k] += dp[i - 1][k - j];
        }
      }
    }

    /*for(int i = 0; i <= n; ++i){
        for(int k = 0; k <= s; ++k){
            std::cout << dp[i][k] << " ";
        }
        std::cout << std::endl;
    }*/

    std::cout << dp[n][s] << std::endl;
  }
}

Error: MLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <map>
#include <set>

std::map<std::pair<std::set<int>, int>, int> dp;
int func(int n, std::set<int> &used, int m) {
  if (n == 0)
    return m == 0;

  {
    auto it = dp.find(std::make_pair(used, m));

    if (it != dp.end())
      return it->second;
  }

  int sum = 0;
  for (int i = 0; i <= 100; ++i) {
    if (m - i >= 0 && !used.count(i)) {
      used.insert(i);

      sum += func(n - 1, used, m - i);

      used.erase(used.find(i));
    }
  }

  return dp[std::make_pair(used, m)] = sum;
}

int main() {
  int n, s;
  std::set<int> used;
  while (std::cin >> n >> s, n != 0 && s != 0) {
    std::cout << func(n, used, s) / 6 << std::endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
long long int a[102][11][1100];

int main() {
  int n, s;
  a[0][0][0] = 1;
  a[0][1][0] = 1;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 1000; k++) {
        a[i + 1][j][k] += a[i][j][k];
        a[i + 1][j + 1][k + i + 1] += a[i][j][k];
      }
    }
  }
  while (1) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    cout << a[100][n][s] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
long long int a[101][11][1100];

int main() {
  int n, s;
  a[0][0][0] = 1;
  a[0][1][0] = 1;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 1000; k++) {
        a[i + 1][j][k] += a[i][j][k];
        a[i + 1][j + 1][k + i + 1] += a[i][j][k];
      }
    }
  }
  while (1) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    cout << a[100][n][s] << endl;
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

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

int dp[1110][10] = {};

signed main() {
  int n, s;
  while (1) {
    cin >> n >> s;
    if (n + s == 0)
      break;
    rep(j, 0, s + 1) rep(k, 0, n + 1) dp[j][k] = 0;
    dp[0][0] = 1;
    dp[0][1] = 1;

    rep(i, 1, 101) {
      repb(j, s, 0) {
        rep(k, 0, 10) {
          // dp[i][j][k]+=dp[i-1][j][k];
          if (j + i <= 1000 && k + 1 <= n) {
            dp[j + i][k + 1] += dp[j][k];
          }
        }
      }
    }
    o(dp[s][n]);
  }
}

Error: -11

Fixed submission:

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

int n, s, dp[11][1001];

int main() {
  dp[0][0] = 1;
  rep(i, 0, 101) {
    repb(j, 10, 0) {
      for (int k = 0; i + k < 1001; k++) {
        dp[j + 1][k + i] += dp[j][k];
      }
    }
  }
  while (cin >> n >> s, n | s)
    o(dp[n][s]);
}