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

#include <iostream>

using namespace std;

typedef long long ll;
const int MAX_N = 15;
const int MAX_S = 1110;
const int MAX_ADD = 110;
int n, s;
ll memo[MAX_ADD][MAX_N][MAX_S];

ll rec(ll add, ll num, ll sum) {
  if (memo[add][num][sum] >= 0)
    return memo[add][num][sum];

  if (num == n && sum == s)
    return 1;
  if (add > 100 || sum > s || num > n)
    return 0;

  ll res = 0;
  res += rec(add + 1, num, sum);
  res += rec(add + 1, num + 1, sum + add);

  return memo[add][num][sum] = res;
}

int main() {
  while (cin >> n >> s, n || s) {
    for (int i = 0; i < MAX_ADD; i++)
      for (int j = 0; j < MAX_N; j++)
        for (int k = 0; k < MAX_S; k++)
          memo[i][j][k] = -1;

    cout << rec(0, 0, 0) << endl;
  }

  return 0;
}

Error: 0
3 6
3 1


Fixed submission:

#include <iostream>

using namespace std;

const int MAX_N = 15;
const int MAX_S = 1110;
const int MAX_ADD = 110;
int n, s;
int memo[MAX_ADD][MAX_N][MAX_S];

int rec(int add, int num, int sum) {
  if (memo[add][num][sum] >= 0)
    return memo[add][num][sum];

  if (num == n && sum == s)
    return 1;
  if (add > 100 || sum > s || num > n)
    return 0;

  int res = 0;
  res += rec(add + 1, num, sum);
  res += rec(add + 1, num + 1, sum + add);

  return memo[add][num][sum] = res;
}

int main() {
  while (cin >> n >> s, n || s) {
    cerr << n << " " << s << endl;
    for (int i = 0; i < MAX_ADD; i++)
      for (int j = 0; j < MAX_N; j++)
        for (int k = 0; k < MAX_S; k++)
          memo[i][j][k] = -1;

    cout << rec(0, 0, 0) << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;

long long int dp[11][1001];
void q97() {
  dp[0][0] = 1;
  for (int i = 0; i < 101; i++) {
    for (int j = 9; j >= 0; j--) {
      for (int k = 0; i + k < 1001; k++) {
        dp[j + 1][k + i] += dp[j][k];
      }
    }
  }

  int n, s;
  for (; cin >> n >> s;) {
    if (!n && !s)
      break;
    cout << dp[n][s] << endl;
  }
}

int main() {
  q97();
  return 0;
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#define max(a, b)                                                              \\
  { a > b ? a : b }
using namespace std;

//????´????????????§?????????????????????
#define P 101
#define MAX 1000000000
int cnt;
void rec(int prev_i, int n, int s) {

  if (n == 1) {
    if (s > prev_i && s <= 100)
      cnt++;
    return;
  }

  /*
          if (n == 2) {
                  if ((s - 1) / 2 - prev_i > 0) {
                          cnt += (s - 1) / 2 - prev_i;
                  }
                  return;
          }
  */

  for (int i = max(prev_i + 1, s - 100 * n); i < P; i++) {
    if (s - i * n < 0)
      return;
    rec(i, n - 1, s - i);
  }
}

void q97() {
  int n, s;
  for (; cin >> n >> s;) {
    if (!n && !s)
      break;
    cnt = 0;
    rec(-1, n, s);
    cout << cnt << endl;
  }
}

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

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

using namespace std;

int n, s;
long long int dp[11][1001] = {0};

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

  for (int i = 0; i <= 100; i++) {
    for (int j = 9; j >= 0; j--) {
      for (int k = 0; k <= 1000 - i; k++) {
        dp[j + 1][k + i] += dp[j][k];
      }
    }
  }

  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    cout << dp[n][s] << endl;
  }
}

Error: TLE

Fixed submission:

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

using namespace std;

int n, s;

int num[101];

int sum(int count, int position, int now) {

  if (count == 0 && now == s)
    return 1;
  else if (count == 0)
    return 0;
  if (position == 100)
    return 0;

  int ari, nasi;
  ari = sum(count - 1, position + 1, now + position);
  nasi = sum(count, position + 1, now);
  return ari + nasi;
}

int main() {

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

  while (cin >> n >> s) {

    if (n == 0 && s == 0)
      break;

    cout << sum(n, 0, 0) << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long dp[1001][101][10];
bool used[101];

long long solve(int s, int upper, int n) {
  if (n == 0) {
    return s == 0 ? 1 : 0;
  }
  if (upper < 0) {
    return 0;
  }
  if (0 <= dp[s][upper][n]) {
    return dp[s][upper][n];
  }
  long long ret = 0;
  for (int i = upper; i >= 0; --i) {
    if (!used[i] && 0 <= s - i) {
      used[i] = true;
      ret += solve(s - i, i - 1, n - 1);
      used[i] = false;
    }
  }
  return dp[s][upper][n] = ret;
}

int main() {
  int n, s;
  for (int i = 0; i < 1001; ++i) {
    for (int j = 0; j < 101; ++j) {
      for (int k = 0; k < 10; ++k) {
        dp[i][j][k] = -1;
      }
    }
  }
  memset(used, false, sizeof used);
  while (cin >> n >> s, n) {
    cout << solve(s, 100, n) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

long long dp[1001][101][10];
bool used[101];

long long solve(int s, int upper, int n) {
  if (n == 0) {
    return s == 0 ? 1 : 0;
  }
  if (0 < dp[s][upper][n]) {
    return dp[s][upper][n];
  }
  long long ret = 0;
  for (int i = upper; i >= 0; --i) {
    if (!used[i] && 0 <= s - i) {
      used[i] = true;
      ret += solve(s - i, i - 1, n - 1);
      used[i] = false;
    }
  }
  return dp[s][upper][n] = ret;
}

int main() {
  int n, s;
  memset(dp, 0, sizeof dp);
  memset(used, false, sizeof used);
  while (cin >> n >> s, n) {
    cout << solve(s, 100, n) << endl;
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n, s;
int dfs(int cou, int now, int before);

int main() {
  while (1) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    int ans = 0;
    for (int i = 0; i < 10; i++) {
      ans = dfs(0, 0, -1);
    }
    cout << ans << endl;
  }
}

int dfs(int cou, int now, int before) {
  if (cou == n) {
    if (now == s) {
      return 1;
      cout << before << endl;
    } else
      return 0;
  }
  int num = 0;
  for (int i = before + 1; i < 100; i++) {
    if (now + i <= s) {
      num += dfs(cou + 1, now + i, i);
    }
  }
  return num;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <string>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

long long dp[20][1200][200];

long long f(int n, int s, int next) {
  if (n == 0 && s == 0)
    return 1;
  if (n < 0 || s < 0)
    return 0;
  if (next > s)
    return 0;
  if (dp[n][s][next] != -1) {
    return dp[n][s][next];
  }
  long long res = 0;
  loop(i, next, 101) { res += f(n - 1, s - i, i + 1); }
  return dp[n][s][next] = res;
}

int main() {
  int n, k;
  while (cin >> n >> k, n || k) {
    rep(i, 20) rep(j, 1200) rep(l, 200) dp[i][j][l] = -1;
    cout << f(n, k, 0) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <string>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int dp[10][1001][101];

int f(int n, int s, int next) {
  if (n == 0 && s == 0)
    return 1;
  if (n < 0)
    return 0;
  if (dp[n][s][next] != -1)
    return dp[n][s][next];
  int res = 0;
  loop(i, next + 1, s + 1) { res += f(n - 1, s - i, i); }
  return res;
}

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

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long lli;

const int MAXN = 10;
const int MAXS = 1005;
lli mem[MAXN][MAXS][101];

lli rec(lli n, lli s, lli p) {
  lli &res = mem[n][s][p];
  if (res != -1)
    return res;
  if (n == 0) {
    return res = (s == 0) ? 1 : 0;
  }
  res = 0;
  for (lli i = p + 1; i <= 100 && s - i >= 0; ++i) {
    res += rec(n - 1, s - i, i);
  }
  return res;
}

int main() {
  lli n, s;
  while (cin >> n >> s && (n | s)) {
    fill(mem[0][0], mem[MAXN][0], -1LL);
    cout << rec(n, s, -1) << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
typedef long long lli;

const int MAXN = 10;
const int MAXS = 1005;
lli mem[MAXN][MAXS][MAXS];

lli rec(lli n, lli s, lli p) {
  lli &res = mem[n][s][p];
  if (res != -1)
    return res;
  if (n == 0) {
    return res = (s == 0) ? 1 : 0;
  }
  res = 0;
  for (lli i = p + 1; i <= s; ++i) {
    res += rec(n - 1, s - i, i);
  }
  return res;
}

int main() {
  lli n, s;
  while (cin >> n >> s && (n | s)) {
    fill(mem[0][0], mem[MAXN][0], -1);
    cout << rec(n, s, -1) << endl;
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
long int dp[1001][101][10];
long int dfs(int s, int p, int d) {
  if (!s && !d)
    return 1;
  if (s < 0 || d < 0 || p < 0)
    return 0;
  if (dp[s][p][d] != -1)
    return dp[s][p][d];
  return dp[s][p][d] = dfs(s - p, p - 1, d - 1) + dfs(s, p - 1, d);
}
int main() {
  int d, s;
  memset(dp, -1, sizeof(dp));
  while (cin >> d >> s, d)
    cout << dfs(s, 100, d) << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int dp[1001][10][101], x, y;
int r(int s, int d, int t) {
  if (t < 0 && !s && !d)
    return 1;
  if (t < 0)
    return 0;
  if (dp[s][d][t] > -1)
    return dp[s][d][t];
  return dp[s][d][t] = r(s - t, d - 1, t - 1) + r(s, d, t - 1);
}
int main() {
  memset(dp, -1, sizeof(dp));
  while (cin >> x >> y, x)
    cout << r(y, x, 100) << endl;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int n, s;
int flg[101] = {};
long long ans;
int count;
int dp[11][1001][101];
long long test;

void saiki(int sum, int mae, int kai) {
  count++;
  if (kai == n && sum == s)
    ans++, dp[kai][sum][mae]++;
  if (kai == n && sum != s)
    dp[kai][sum][mae] = -1;
  //  if(kai == n) cout <<"kai="<< kai<<" sum="<< sum <<" mae="<< mae <<"
  //  result="<<dp[kai][sum][mae]<< endl;

  if (kai < n && sum <= s) {
    for (int i = 0; i <= 100; i++) {
      if (flg[i] == 0 && mae < i && sum + i <= s) {
        if (dp[kai + 1][sum + i][i] == -1)
          continue;
        else if (dp[kai + 1][sum + i][i] > 0) {
          ans += dp[kai + 1][sum + i][i];
          dp[kai][sum][mae] += dp[kai + 1][sum + i][i];
          continue;
        }
        flg[i] = 1;
        saiki(sum + i, i, kai + 1);
        flg[i] = 0;
        if (kai == 0 && dp[kai + 1][sum + i][i] > 0)
          test += dp[kai + 1][sum + i][i];
        if (dp[kai + 1][sum + i][i] >= 1)
          dp[kai][sum][mae] += dp[kai + 1][sum + i][i];
        // cout <<"kai="<< kai<<" sum="<< sum <<" i="<< i <<"
        // result="<<dp[kai+1][sum+i][i]<< endl;
      }
    }
    if (dp[kai][sum][mae] == 0)
      dp[kai][sum][mae] = -1;
  }
}

int main() {

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

    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= s; j++)
        for (int k = 0; k <= 100; k++)
          dp[i][j][k] = 0;
    for (int i = 0; i <= 100; i++)
      flg[i] = 0;

    ans = 0;
    count = 0;
    test = 0;
    saiki(0, -1, 0);
    // cout << ans << endl;
    // cout <<count << endl;
    cout << test << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n, s;
int flg[101] = {};
int ans;
int count;
int dp[11][1001][101];

void saiki(int sum, int mae, int kai) {
  count++;

  if (kai == n && sum == s)
    ans++, dp[kai][sum][mae] = 1;
  if (kai == n && sum != s)
    dp[kai][sum][mae] = 2;
  //  if(kai == n) cout <<"kai="<< kai<<" sum="<< sum <<" mae="<< mae <<"
  //  result="<<dp[kai][sum][mae]<< endl;

  if (kai < n && sum <= s) {
    for (int i = 0; i <= 100; i++) {
      if (flg[i] == 0 && mae < i && sum + i <= s) {
        if (dp[kai + 1][sum + i][i] == 2)
          continue;
        flg[i] = 1;
        saiki(sum + i, i, kai + 1);
        flg[i] = 0;
        if (dp[kai][sum][mae] == 0 || dp[kai + 1][sum + i][i] == 1)
          dp[kai][sum][mae] =
              dp[kai + 1][sum + i]
                [i]; //,cout <<"kai="<< kai<<" sum="<< sum <<" i="<< i <<"
                     //result="<<dp[kai+1][sum+i][i]<< endl;
      }
    }
  }
}

int main() {

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

    for (int i = 0; i <= n; i++)
      for (int j = 0; j <= s; j++)
        for (int k = 0; k <= 100; k++)
          dp[i][j][k] = 0;

    ans = 0;
    saiki(0, -1, 0);
    cout << ans << endl;
    //  cout <<count << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

#define llong long long
llong int n, s;
llong int ans;
llong int memo[101][10][1000];

llong int solve(int now, int d, int sum) {
  if (d == 0) {
    llong int ret = 0;
    for (int i = 0; i <= 100; i++) {
      ret += solve(i, 1, i);
    }

    return ret;
  }

  if (memo[now][d][sum] != -1)
    return memo[now][d][sum];

  if (d == n) {
    if (sum == s)
      return memo[now][d][sum] = 1;
    else
      return memo[now][d][sum] = 0;
  }
  if (d < n && sum >= s)
    return memo[now][d][sum] = 0;

  llong int ret = 0;
  for (int i = now + 1; i <= 100; i++) {
    ret += solve(i, d + 1, sum + i);
  }

  return memo[now][d][sum] = ret;
}

int main() {

  while (cin >> n >> s, n) {
    fill_n(**memo, 101 * 10 * 1000, -1);
    cout << solve(0, 0, 0) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define llong long long
int n, s;
int ans;
int memo[10][101][1000];

int solve(int before, int d, int sum) {
  // if(before != -1){
  // 	if(memo[before][sum] != -1) return memo[before][sum];

  // 	if(d == n){
  // 		if(sum == s){
  // 			return memo[before][sum] = 1;
  // 		}else{
  // 			return memo[before][sum] = 0;
  // 		}
  // 	}
  // 	if(sum > s) return memo[before][sum] = 0;

  // 	llong int ret = 0;
  // 	int end = (s < 100 ? s : 100);
  // 	for(int i = 0; i <= end ; i++){
  // 		if(i <= before)continue;
  // 		ret += solve(i, d + 1, sum + i);
  // 		cout << d << " " << before << " " << i << " " << sum << " " << ret <<
  // endl;
  // 	}

  // 	return memo[before][sum] = ret;
  // }

  // llong int ret = 0;
  // int end (s < 100 ? s : 100);
  // for(int i = 0; i <= end; i++){
  // 	ret += solve(i, d +1, sum + i);
  // }

  // return ret;
  int end = (s < 100 ? s : 100);

  if (before == -1) {
    int ret = 0;
    for (int i = 0; i < end; i++) {
      ret += solve(i, d + 1, sum + i);
    }
    return ret;
  }

  if (memo[before][d][sum] != -1)
    return memo[before][d][sum];

  if (d == n) {
    if (sum == s) {
      return memo[before][d][sum] = 1;
    } else
      return memo[before][d][sum] = 0;
  }
  if (d < n && sum >= s)
    return memo[before][d][sum] = 0;

  int ret = 0;
  for (int i = 0; i < end; i++) {
    if (i <= before)
      continue;
    ret += solve(i, d + 1, sum + i);
  }

  return memo[before][d][sum] = ret;
}

int main() {

  while (cin >> n >> s, n) {
    fill_n(**memo, 10 * 101 * 1000, -1);
    cout << solve(-1, 0, 0) << endl;
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int n, s;
long long int a[10][1001][101];

long long int solver(int d, int sum, int p) {
  if (a[d][sum][p] >= 0)
    return a[d][sum][p];

  if (d == n) {
    if (sum == s) {
      return a[d][sum][p] = 1;
    } else {
      return a[d][sum][p] = 0;
    }
  }

  long long int b = 0;
  for (int i = p; i <= 100; i++) {
    b += solver(d + 1, sum + i, i + 1);
  }
  a[d][sum][p] = b;
  return b;
}
int main() {
  while (cin >> n >> s, n) {
    fill_n(**a, 10 * 1001 * 101, -1);
    cout << solver(0, 0, 0) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int n, s;
int check[11][1001];
bool memo[11][1001];

int solve(int d, int sum, int num) {
  int ret = 0;
  if (s - sum > 1000 * (n - d))
    return 0;
  ;
  if (sum > s)
    return 0;
  if (d == n) {
    if (sum == s) {
      return 1;
    } else {
      return 0;
    }
  }
  for (int j = num; j <= 1000; j++) {
    ret += solve(d + 1, sum + j, j + 1);
  }
  return ret;
}

int main() {
  fill_n(*check, 11 * 1001, 0);
  fill_n(*check, 11 * 1001, 0);
  while (cin >> n >> s, n) {
    cout << solve(0, 0, 0) << endl;
  }
  return 0;
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
long long dp[9][1100][110] = {0};

int main() {
  for (int i = 0; i < 101; i++) {
    dp[0][i][i] = 1;
  }
  for (int i = 1; i < 9; i++) {
    for (int j = 0; j < 1100; j++) {
      for (int k = 0; k < 101; k++) {
        for (int l = k + 1; l < 101; l++) {
          if (j - l >= 0) {
            dp[i][j][l] += dp[i - 1][j - l][k];
          }
        }
      }
    }
  }
  int n, m;
  while (cin >> n >> m, n != 0 || m != 0) {
    long long tmp = 0;
    for (int i = 0; i < 110; i++) {
      tmp += dp[n - 1][m][i];
    }
    cout << tmp << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
long int dp[9][1100][110] = {0};

int main() {
  for (int i = 0; i < 101; i++) {
    dp[0][i][i] = 1;
  }
  for (int i = 1; i < 9; i++) {
    for (int j = 0; j < 1100; j++) {
      for (int k = 0; k < 101; k++) {
        for (int l = k + 1; l < 101; l++) {
          if (j - l >= 0) {
            dp[i][j][l] += dp[i - 1][j - l][k];
          }
        }
      }
    }
  }
  int n, m;
  while (cin >> n >> m) {
    long int tmp = 0;
    for (int i = 0; i < 110; i++) {
      tmp += dp[n - 1][m][i];
    }
    cout << tmp << endl;
  }
}
Problem p00097 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

typedef long long int ll;

ll dp[102][11][1001];

int main() {
  int n, s;

  while (cin >> n >> s, n || s) {
    for (int i = 0; i < 102; i++) {
      for (int j = 0; j < 11; j++) {
        for (int k = 0; k < 1001; k++) {
          dp[i][j][k] = 0;
        }
      }
    }

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

    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= n; j++) {
        for (int k = 0; k <= s; k++) {
          dp[i + 1][j][k] += dp[i][j][k];
          if (k + i > s)
            continue;
          dp[i + 1][j + 1][k + i] += dp[i][j][k];
        }
      }
    }

    cout << dp[101][n][s] << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

typedef long long int ll;

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

int main() {
  int n, s;

  while (cin >> n >> s, n || s) {
    for (int i = 0; i < 102; 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 < 102; i++) {
      for (int j = 0; j <= n; j++) {
        for (int k = 0; k <= s; k++) {
          dp[i + 1][j][k] += dp[i][j][k];
          if (k + i > s)
            continue;
          dp[i + 1][j + 1][k + i] += dp[i][j][k];
        }
      }
    }

    cout << dp[101][n][s] << endl;
  }

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

#include <iostream>
using namespace std;

typedef long long ll;

// dp[n][s] := n個の数字を使って合計がsのときの組合せ数
ll dp[10][1010] = {0};

int main() {
  dp[0][0] = 1;
  for (int i = 0; i <= 100; i++) {
    for (int j = 1000; j >= 0; j--) {
      for (int k = 9; k >= 1; k--) {
        if (j - i >= 0) {
          dp[k][j] += dp[k - 1][j - i];
        }
      }
    }
  }

  int n, s;
  while (cin >> n >> s, n || s) {
    cout << dp[n][s] << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int f[10] = {0, 100, 199, 297, 394, 490, 585, 679, 772, 864};

int dfs(int n, int s, int k) {
  if (n == 0) {
    return (s == 0) ? 1 : 0;
  }

  if (f[n] < s)
    return 0;
  if (s < 0)
    return 0;

  int res = 0;
  for (int i = k; i <= 100; i++) {
    res += dfs(n - 1, s - i, i + 1);
  }
  return res;
}

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

#include <iostream>
using namespace std;

long long int D = 10000000000;
long long int dp[10][102][1000];
int n, s;

void set() {
  int x, y, z;
  for (x = 0; x < 10; x++) {
    for (y = 0; y < 102; y++) {
      for (z = 0; z <= 1000; z++) {
        dp[x][y][z] = 0;
      }
    }
  }
  dp[0][0][0] = 1;
  for (x = 0; x < 10; x++) {
    for (y = 1; y <= 101; y++) {
      for (z = 0; z < 1000; z++) {
        dp[x][y][z] += dp[x][y - 1][z];
        if (x && z >= y - 1) {
          dp[x][y][z] += dp[x - 1][y - 1][z - y + 1];
        }
        dp[x][y][z] %= D;
      }
    }
  }
}

int main() {
  set();
  while (cin >> n >> s, n | s) {
    long long int ans = 0;
    cout << dp[n][101][s] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int dp[10][101][901];
//   n_used, m_used, sum

void set() {
  int x, y, z, v;
  for (z = 0; z < 10; z++) {
    for (x = 0; x <= 100; x++) {
      for (y = 0; y <= 900; y++) {
        dp[z][x][y] = 0;
      }
    }
  }
  for (x = 0; x <= 100; x++) {
    dp[1][x][x] = 1;
  }
  for (z = 1; z < 9; z++) {
    for (x = 0; x < 100; x++) {
      for (y = 0; y < 900; y++) {
        for (v = x + 1; v <= 100; v++) {
          dp[z + 1][v][y + v] += dp[z][x][y];
        }
      }
    }
  }
}

int main() {
  int a, b;
  set();
  while (cin >> a >> b, a || b) {
    int ans = 0;
    for (int c = 1; c <= 100; c++) {
      ans += dp[a][c][b];
    }
    cout << ans << endl;
  }
  return 0;
}