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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int ab[2050];

int main(void) {
  int n;

  for (int a = 0; a <= 1000; a++) {
    for (int b = 0; b <= 1000; b++) {
      ab[a + b]++;
    }
  }

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

    int ret = 0;
    for (int cd = 0; cd <= 2000; cd++) {
      if (n - cd >= 0 && n - cd <= 2000) {
        ret += ab[cd] * ab[n - cd];
      }
    }
    cout << ret << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int ab[2050];

int main(void) {
  int n;

  for (int a = 0; a <= 1000; a++) {
    for (int b = 0; b <= 1000; b++) {
      ab[a + b]++;
    }
  }

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

    int ret = 0;
    for (int cd = 0; cd <= 2000; cd++) {
      if (n - cd >= 0) {
        ret += ab[cd] * ab[n - cd];
      }
    }
    cout << ret << endl;
  }

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

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

int main(int argc, char *argv[]) {
  int n;
  int a_add_b[2001] = {0};

  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a_add_b[i + j]++;
    }
  }

  while (scanf("%d", &n) != EOF) {
    long long int ans = 0;
    for (int i = 0; i <= 2000; i++) {
      if (0 <= n - i && n - i <= 2000)
        ans += a_add_b[i] * a_add_b[n - i];
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main(int argc, char *argv[]) {
  int n;
  int a_add_b[2001] = {0};

  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a_add_b[i + j]++;
    }
  }

  while (scanf("%d", &n) != EOF) {
    long long int ans = 0;
    for (int i = 0; i <= n; i++) {
      ans += a_add_b[i] * a_add_b[n - i];
    }
    std::cout << ans << std::endl;
  }
  return 0;
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  map<int, int> hash;
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++)
      hash[i + j]++;
  for (; cin >> n;) {
    int ans = 0;
    for (int i = 0; i <= n / 2; i++) {
      ans += hash[i] * hash[n - i];
      if (i != n - i)
        ans += hash[i] * hash[n - i];
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  map<int, int> hash;
  for (int i = 0; i <= 1000; i++)
    for (int j = 0; j <= 1000; j++)
      hash[i + j]++;

  for (; cin >> n;) {
    int ans = 0;
    for (int i = 0; i <= n; i++)
      for (int j = 0; i + j <= n; j++) {
        ans += hash[n - i - j];
      }
    cout << ans << endl;
  }
}
Problem p00096 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

using namespace std;

int c[2001], res[4001];

int main(void) {

  for (int i = 0; i < 1001; i++)
    for (int j = 0; j < 1001; j++)
      c[i + j]++;

  for (int i = 0; i < 2001; i++)
    for (int j = 0; j < 2001; j++)
      res[i + j] += c[i] * c[j];

  int n;
  while (cin >> n)
    cout << res[n] << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

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

using namespace std;

int main(void) {

  int n;
  vector<int> r, l;

  for (int i = 0; i < 1001; i++)
    for (int j = 0; j < 1001; j++)
      l.push_back(i + j);

  sort(all(l));

  while (cin >> n, n) {

    r.clear();

    for (int i = 0; i < 1001; i++)
      for (int j = 0; j < 1001; j++)
        r.push_back(n - i - j);

    sort(all(r));

    int cnt = 0;
    for (int i = 0; i < l.size(); i++)
      cnt += upper_bound(all(r), l[i]) - lower_bound(all(r), l[i]);

    cout << cnt << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  int n;
  long long int g[5][4001] = {0, 0};
  g[0][0] = 1;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j <= 4000; j++) {
      if (g[i][j]) {
        for (int k = 0; k <= 1000; k++)
          g[i + 1][j + k] += g[i][j];
      }
    }
  }
  while (cin >> n) {
    cout << g[4][n] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    long long int count = 0;
    int cou = 0;
    int q[n * n * n];
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        if (i + j > n)
          break;
        q[cou++] = i + j;
      }
    }
    sort(q, q + cou);
    for (int i = 0; i < cou; i++) {
      for (int j = 0; j < cou; j++) {
        if (q[i] + q[j] == n)
          count++;
        // if(q[i]+q[j]>n) continue;
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

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

map<int, long long int> dp[111][111];

int main() {
  int N, S;
  while (cin >> N >> S, N || S) {
    for (int i = 0; i < 111; i++)
      for (int j = 0; j < 111; j++)
        dp[i][j].clear();
    dp[0][0][0] = 1;
    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= N; j++) {
        for (auto k : dp[i][j]) {
          dp[i + 1][j + 1][k.first + i] += k.second;
          dp[i + 1][j][k.first] += k.second;
        }
      }
    }

    cout << dp[101][N][S] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int dfs(int n, int s, int i) {
  if (n == 0 && s == 0)
    return 1;
  if (s < i)
    return 0;
  else {
    int res = 0;
    res = res + dfs(n, s, i + 1);
    res = res + dfs(n - 1, s - i, i + 1);
    return res;
  }
}

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

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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
#define INF 1e+8
#define EPS 1e-7
#define PB push_back
#define fi first
#define se second
#define ll long long
#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
typedef pair<int, int> Pii;
typedef vector<int> vi;
int main() {
  ll dp[10][10000] = {{0}};
  dp[0][0] = 1;
  rep(i, 101) {
    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 (scanf("%d%d", &n, &s), (n | s)) {
    printf("%lld\\n", dp[n][s]);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
#define INF 1e+8
#define EPS 1e-7
#define PB push_back
#define fi first
#define se second
#define ll long long
#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
typedef pair<int, int> Pii;
typedef vector<int> vi;
int main() {
  ll dp[10][10000] = {{0}};
  dp[0][0] = 1;
  rep(i, 101) {
    for (int j = 1000; j >= 0; j--) {
      for (int k = 10; k > 0; k--) {
        dp[k][j] += dp[k - 1][j - i];
      }
    }
  }
  int n, s;
  while (scanf("%d%d", &n, &s), (n | s)) {
    printf("%d\\n", dp[n][s]);
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>

using namespace std;

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

typedef tuple<int, int, int> state;
map<state, long long> dp;

long long f(int i, int n, int rest) {
  // trivial
  if (0) {
  } else if (n == 0 && rest == 0)
    return 1;
  else if (i > 100 || n < 0 || rest < 0)
    return 0;

  // not trivial
  else {
    long long res;
    state s;
    s = state(i, n, rest);
    if (dp.count(s))
      return dp[s];
    else
      res = f(i + 1, n - 1, rest - i) + f(i + 1, n, rest);
    dp[s] = res;
    return res;
  }
}

int main() {
  int n, s;
  while (1) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    cout << f(0, n, s) << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>

using namespace std;

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

typedef tuple<int, int, int> state;
map<state, int> dp;

int f(int i, int n, int rest) {
  int res;
  if (n == 0 || i > rest)
    res = 0;
  else if (i == 100) {
    if (n == 1 && rest == 100)
      res = 1;
    else
      res = 0;
  } else if (n == 1 && i == rest)
    res = 1;
  else
    res = f(i + 1, n - 1, rest - i) + f(i + 1, n, rest);
  // cout<<
  //     " i="<<i<<
  //     " n="<<n<<
  //     " rest="<<rest<<
  //     " res="<<res<<
  //     endl;
  return res;
}

int main() {
  int n, s;
  while (1) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    cout << f(0, n, s) << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

using lint = long long;

lint n, s;
lint dp[1001][101][11];

lint dfs(int sum = 0, int num = 0, int cnt = 0) {
  if (cnt == n)
    return sum == s;
  if (num > 100 || sum > s)
    return 0;

  lint &ret = dp[sum][num][cnt];
  if (~ret)
    return ret;

  ret = dfs(sum, num + 1, cnt) + dfs(sum + num, num + 1, cnt + 1);

  return ret;
}

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

Error: MLE

Fixed submission:

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

using lint = long long;

lint n, s;
lint dp[1001][101][101];

lint dfs(int sum = 0, int num = 0, int cnt = 0) {
  if (cnt == n)
    return sum == s;
  if (num > 100 || sum > s)
    return 0;

  lint &ret = dp[sum][num][cnt];
  if (~ret)
    return ret;

  ret = dfs(sum, num + 1, cnt) + dfs(sum + num, num + 1, cnt + 1);

  return ret;
}

int main() {
  while (cin >> n >> s, n + s) {
    memset(dp, -1, sizeof(dp));
    cout << dfs() << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>

long long int
calPattern(int lower, int n, int sum,
           std::vector<std::vector<std::vector<long long int>>> &memo) {
  if (n == 0 && sum == 0)
    return 1;
  if (n == 0 && sum != 0)
    return 0;
  if (lower > 100)
    return 0;
  if (memo[lower][n][sum] < 0) {
    memo[lower][n][sum] = 0;
    for (auto i = lower; i <= 100 && i <= sum; ++i) {
      memo[lower][n][sum] += calPattern(i + 1, n - 1, sum - i, memo);
    }
  }
  return memo[lower][n][sum];
}
int main() {
  std::vector<std::vector<std::vector<long long int>>> memo(
      101, std::vector<std::vector<long long int>>(
               10, std::vector<long long int>(1001, -1)));
  int n, s;
  std::cin >> n >> s;
  while (n != 0) {
    std::cout << calPattern(0, n, s, memo) << std::endl;
    std::cin >> n >> s;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int aol97(int n, int s) {
  if (0 > s or n <= 0 or (n * (n - 1) / 2 > s)) {
    return 0;
  } else if (n * (n - 1) / 2 == s or n == 1) {
    return 1;
  } else {
    return aol97(n - 1, s - 1) + aol97(n, s - n) - aol97(n - 2, s - 2);
  }
}
int main() {
  int n, s;
  cin >> n >> s;
  while (n != 0 or s != 0) {
    cout << aol97(n, s) << "\\n";
    cin >> n >> s;
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>

typedef long ll;

ll memo[10][1001][101];
ll dfs(int n, int s, int x) {
  ll pat = 0;
  int i;
  if (n == 0)
    return s == 0;
  if (s < 0)
    return 0;
  if (x > 100)
    return 0;
  if (memo[n][s][x] != -1)
    return memo[n][s][x];

  for (i = x; i <= 100; i++) {
    pat += dfs(n - 1, s - i, i + 1);
  }
  return memo[n][s][x] = pat;
}

int main(void) {
  int N, S;
  while (scanf("%d %d", &N, &S), N || S) {
    memset(memo, -1, sizeof(memo));
    printf("%ld\\n", dfs(N, S, 0));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>

typedef long ll;

ll memo[10][1010];
ll dfs(int n, int s, int x) {
  ll pat = 0;
  if (n == 0)
    return s == 0;
  if (s < 0)
    return 0;
  if (x > 100)
    return 0;
  if (memo[n][s] != -1)
    return memo[n][s];

  for (; x <= 100; x++) {
    pat += dfs(n - 1, s - x, x + 1);
  }
  return pat;
}

int main(void) {
  int N, S;
  while (scanf("%d %d", &N, &S), N || S) {
    memset(memo, -1, sizeof(memo));
    printf("%ld\\n", dfs(N, S, 0));
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

int n, s;

bool input() {
  cin >> n >> s;
  return n != 0;
}

const int N = 101;
const int M = 10;
const int K = 1001;

ll memo[N + 10][M][K];

ll saiki(int st, int rn, int rs) {

  if (memo[st][rn][rs] != -1)
    return memo[st][rn][rs];

  if (rn == 0) {
    if (rs == 0)
      return 1;
    return 0;
  }

  ll ret = 0;
  reps(i, st, N) {
    if (rs - i < 0)
      break;
    ret += saiki(i + 1, rn - 1, rs - i);
  }

  //  printf("st=%d rn=%d rs=%d ret=%d\\n",st,rn,rs,ret);

  return memo[st][rn][rs] = ret;
}

ll solve() {
  rep(i, N + 10) rep(j, M) rep(k, K) memo[i][j][k] = -1;

  return saiki(0, n, s);
}

int main() {
  while (input()) {
    cout << solve() << endl;
  }
}

Error: 0

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

int n, s;

bool input() {
  cin >> n >> s;
  return n != 0;
}

const int N = 101;
const int M = 10;
const int K = 1001;

ll memo[N][M][K];

ll saiki(int st, int rn, int rs) {

  if (memo[st][rn][rs] != -1)
    return memo[st][rn][rs];

  if (rn == 0) {
    if (rs == 0)
      return 1;
    return 0;
  }

  ll ret = 0;
  reps(i, st, N) {
    if (rs - i < 0)
      break;
    ret += saiki(i + 1, rn - 1, rs - i);
  }

  //  printf("st=%d rn=%d rs=%d ret=%d\\n",st,rn,rs,ret);

  return memo[st][rn][rs] = ret;
}

ll solve() {
  rep(i, N) rep(j, M) rep(k, K) memo[i][j][k] = -1;

  return saiki(0, n, s);
}

int main() {
  while (input()) {
    cout << solve() << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
// const int INF = 1e8;
using namespace std;

int main() {
  int n, s;
  while (cin >> n >> s, n) {
    long long dp[10][2005] = {{0}};
    dp[0][0] = 1;
    rep(j, 101) {
      for (int i = n; i >= 0; i--) {
        for (int k = s; k >= 0; k--) {
          dp[i + 1][k + j] += dp[i][k];
        }
      }
    }
    cout << dp[n][s] << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
// const int INF = 1e8;
using namespace std;

int main() {
  int n, s;
  while (cin >> n >> s, n) {
    long long dp[10][1005] = {{0}};
    dp[0][0] = 1;
    rep(j, 101) {
      for (int i = n; i >= 0; i--) {
        for (int k = s; k >= 0; k--) {
          dp[i + 1][k + j] += dp[i][k];
        }
      }
    }
    cout << dp[n][s] << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Memory Limit Exceeded


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < (n); i++)
#define loop(i, a, n) for (i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

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

ll dp[2][105][6000];

int main(void) {
  int i, j, k;
  int n, s;
  while (1) {
    cin >> n >> s;
    if (n == 0)
      break;
    rep(i, 2) rep(j, 101) rep(k, 6000) dp[i][j][k] = 0;
    dp[0][0][0] = 1;

    rep(i, 101) rep(j, 101) rep(k, s + 1) if (dp[i % 2][j][k] > 0) {
      dp[(i + 1) % 2][j][k] += dp[i % 2][j][k];
      dp[(i + 1) % 2][j + 1][min(k + i, s + 1)] += dp[i % 2][j][k];
      dp[i % 2][j][k] = 0;
    }
    cout << dp[i % 2][n][s] << endl;
  }
}


Error: MLE

Fixed submission:


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < (n); i++)
#define loop(i, a, n) for (i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

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

ll dp[105][105][6000];

int main(void) {
  int i, j, k;
  int n, s;
  while (1) {
    cin >> n >> s;
    if (n == 0)
      break;
    rep(i, 101) rep(j, 101) rep(k, 6000) dp[i][j][k] = 0;
    dp[0][0][0] = 1;

    rep(i, 101) rep(j, 101) rep(k, s + 1) if (dp[i][j][k] > 0) {
      dp[i + 1][j][k] += dp[i][j][k];
      dp[i + 1][j + 1][min(k + i, s + 1)] += dp[i][j][k];
    }
    cout << dp[101][n][s] << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long int memo[111][11][1111];

long long int solve(int p, int n, int s) {

  if (!n && !s)
    return memo[p][n][s] = 1;
  if (!n || s < 0)
    return 0;
  if (~memo[p][n][s])
    return memo[p][n][s];

  long long int ans = 0;
  for (int i = p; i < 101; i++)
    ans += solve(i + 1, n - 1, s - i);

  return memo[p][n][s] = ans;
}

int main() {

  memset(memo, -1, sizeof(memo));
  for (int i = 1; i < 10; i++)
    for (int j = 0; j < 1001; j++)
      solve(0, i, j);

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

Error: TLE

Fixed submission:

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

int memo[10][1001][101];

int solve(int n, int s, int p) {

  if (!n && !s)
    return 1;
  if (n < 1 || s < 1)
    return 0;
  if (n * 100 < s)
    return 0;
  if (n == 1 && s - p < 0)
    return 0;
  if (n == 1 && s - p < p)
    return 1;
  if (memo[n][s][p])
    return memo[n][s][p];

  int ans = 0;
  for (int i = p; i < 101; i++)
    ans += solve(n - 1, s - i, i + 1);

  return memo[n][s][p] = ans;
}

int main() {

  int n, s;

  memset(memo, 0, sizeof(memo));
  while (true) {
    cin >> n >> s;
    if (!n && !s)
      break;
    cout << solve(n, s, 0) << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>

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

long long memo[101][10][1001];

// x以下からちょうどk個でsを作る
long long solve(int x, int k, int s) {
  if (k == 0 && s == 0)
    return 1;
  if (s < 0)
    return 0;
  if (x < 0)
    return 0;
  if (k == 0)
    return 0;
  long long &res = memo[x][k][s];
  if (res != -1)
    return res;
  return res = solve(x - 1, k, s) + solve(x - 1, k - 1, s - x);
}

int main() {
  memset(memo, -1, sizeof(memo));
  while (true) {
    int n, s;
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    cout << solve(100, n, s) << endl;
  }
}

Error: 0

Fixed submission:

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

const int MAX_I = 100;
const int MAX_N = 9;
const int MAX_S = 1000;

int dp[MAX_I + 1][MAX_N + 1][MAX_S + 1];

// i以上の数からn個取り出してsを作る組み合わせが何個あるか？
int rec(int i, int n, int s) {
  if (dp[i][n][s] != -1)
    return dp[i][n][s];
  if (n == 1) {
    if (s >= i) {
      return dp[i][n][s] = 1;
    } else {
      return dp[i][n][s] = 0;
    }
  }

  int r = 0;
  for (int j = i; j <= min(s, 100); j++) {
    r += rec(j + 1, n - 1, s - j);
  }
  return dp[i][n][s] = r;
}

int main() {
  int n, s;
  memset(dp, -1, sizeof(dp));
  while (cin >> n >> s, n || s) {
    cout << rec(0, n, s) << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

ll dp[12][102][1001];

int s, n;

int main() {
  dp[0][0][0] = 1;

  for (int i = 0; i <= 9; ++i) {
    for (int j = 0; j <= 100; ++j) {
      for (int k = 0; k <= 1000; ++k) {
        if (dp[i][j][k] == 0)
          continue;
        for (int l = j; l <= 100; ++l) {
          if (k + l < 1001)
            dp[i + 1][l + 1][k + l] += dp[i][j][k];
        }
      }
    }
  }

  while (true) {
    std::cin >> n >> s;
    if (s == 0 && n == 0)
      break;
    ll sum = 0;
    for (int i = 0; i <= 101; ++i)
      sum += dp[n][i][s];
    std::cout << sum << std::endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

typedef long long ll;

ll dp[10][102][1001];

int s, n;

int main() {
  dp[0][0][0] = 1;

  for (int i = 0; i <= 9; ++i) {
    for (int j = 0; j <= 100; ++j) {
      for (int k = 0; k <= 1000; ++k) {
        if (dp[i][j][k] == 0)
          continue;
        for (int l = j; l <= 100; ++l) {
          if (k + l < 1001)
            dp[i + 1][l + 1][k + l] += dp[i][j][k];
        }
      }
    }
  }

  while (true) {
    std::cin >> n >> s;
    if (s == 0 && n == 0)
      break;
    ll sum = 0;
    for (int i = 0; i <= 101; ++i)
      sum += (dp[n][i][s] < 0 ? 0 : dp[n][i][s]);
    std::cout << sum << std::endl;
  }
  return 0;
}