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

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

using namespace std;

int N, S, ans;

void rec(int base, int x, int used) {
  if (x == S && used == N) {
    ans += 1;
    return;
  }
  if (x > S)
    return;
  for (int i = base; i <= 9; i++) {
    rec(i + 1, x + i, used + 1);
  }
}

int main(void) {
  while (1) {
    scanf("%d%d", &N, &S);
    if (N == 0 && S == 0)
      break;
    ans = 0;
    rec(0, 0, 0);
    printf("%d\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int N, S, ans, dp[15][60][15];

void rec(int base, int x, int used) {
  if (x > S || used > N)
    return;
  if (x == S && used == N) {
    if (!dp[base][x][used]) {
      dp[base][x][used] = 1;
      ans += 1;
    }
    return;
  }
  dp[base][x][used] = 1;
  for (int i = base; i <= 9 && x + i <= S; i++) {
    rec(i + 1, x + i, used + 1);
    rec(i + 1, x, used);
  }
}

int main(void) {
  while (1) {
    scanf("%d%d", &N, &S);
    if (N == 0 && S == 0)
      break;
    ans = 0;
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= S; i++) {
      rec(i + 1, i, 1);
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, s;
int Sum_of_Integers(int i, int sum, int v);
int main() {
  while (1) {
    cin >> n >> s;
    if (!n && !s)
      break;
    cout << Sum_of_Integers(0, 0, -1) << endl;
  }
}
int Sum_of_Integers(int i, int sum, int v) {
  int ret = 0;
  if (i > n || sum > s)
    return 0; // あふれたとき
  if (i == n && sum == s)
    return 1;
  for (int j = 0; j <= 9; j++) {
    if (v < j)
      ret += Sum_of_Integers(i + 1, sum + j, j);
  }
  return ret;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int dp[10][101];
int x[101], w = 0;
int n, s;
int Sum_of_Integers(int i, int sum, int v);
int main() {
  while (1) {
    cin >> n >> s;
    if (!n && !s)
      break;
    memset(dp, -1, sizeof(dp)); // -1で初期化
    int k = Sum_of_Integers(0, 0, -1);
    if (k == 0) {
      cout << k << endl;
    } else {
      cout << k << endl;
    }
  }
}
int Sum_of_Integers(int i, int sum, int v) {
  int ret = 0;
  if (i > n || sum > s)
    return 0; // あふれたとき
  if (i == n && sum == s)
    return 1;
  for (int j = v + 1; j <= s; j++) {
    ret += Sum_of_Integers(i + 1, sum + j, j);
  }
  return ret;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n, s;
int count_2;

void dfs(int step, int i, int sum) {
  if (sum > s || step > n)
    return;
  if (i == 10) {
    if (step == n && i == 10 && sum == s) {
      count_2++;
      return;
    } else
      return;
  }
  dfs(step, i + 1, sum);
  dfs(step + 1, i + 1, sum + a[i]);
  return;
}

int main() {
  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    else {
      count_2 = 0;
      dfs(0, 0, 0);
    }
    cout << count_2 << endl;
  }
  // while(1);
  return 0;
}


Error: -11

Fixed submission:


#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n, s;
int count_2;

void dfs(int step, int i, int sum) {
  if (sum > s || step > n)
    return;
  if (step == n && i == 10 && sum == s) {
    count_2++;
    return;
  }
  dfs(step, i + 1, sum);
  dfs(step + 1, i + 1, sum + a[i]);
  return;
}

int main() {
  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    else {
      count_2 = 0;
      dfs(0, 0, 0);
    }
    cout << count_2 << endl;
  }
  // while(1);
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i <= n; i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long LL;
typedef long long int LLI;

int solve(int cnt, int sum, int now);
int n = 0, s = 0;
int main(void) {
  for (;;) {
    cin >> n >> s;

    int ans = solve(0, 0, 0);
    if (n == 0 && s == 0)
      break;
    cout << ans << endl;
  }
  return 0;
}
int solve(int cnt, int sum, int now) {
  if (cnt == 10) {
    return sum == s && now == n;
  }
  int res1 = solve(cnt + 1, sum + cnt, now + 1);
  int res2 = solve(cnt + 1, sum, now);
  return res1 + res2;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i <= n; i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long LL;
typedef long long int LLI;

int solve(int cnt, int sum, int now);
int n = 0, s = 0;
int main(void) {
  for (;;) {
    cin >> n >> s;
    int ans = solve(0, 0, 0);
    cout << ans << endl;
  }
  return 0;
}
int solve(int cnt, int sum, int now) {
  if (cnt == 10) {
    return sum == s && now == n;
  }
  int res1 = solve(cnt + 1, sum + cnt, now + 1);
  int res2 = solve(cnt + 1, sum, now);
  return res1 + res2;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

// dfs
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int ans, n, s;

void dfs(int pos, int t, int sum) {
  if (t == n) {
    if (sum == s)
      ans++;
    return;
  }
  if (pos > 9)
    return;

  dfs(pos + 1, t, sum);
  dfs(pos + 1, t + 1, sum + pos);
}

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

  return 0;
}

Error: -11

Fixed submission:

// dfs
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int ans, n, s;

void dfs(int pos, int t, int sum) {
  if (t == n) {
    if (sum == s)
      ans++;
    return;
  }
  if (t > 9)
    return;

  dfs(pos + 1, t, sum);
  dfs(pos + 1, t + 1, sum + pos);
}

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

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

#include <iostream>
using namespace std;
int count;
void ans(int a, int b, int c, int n, int s) {
  if (b == s && c == n)
    count++;
  if (b > s || c == n)
    goto END;
  for (int i = a + 1; i <= 9; i++)
    ans(i, b + i, c + 1, n, s);
END:;
}
int main() {
  int n, s;
  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    count = 0;
    for (int i = 0; i <= 9; i++)
      ans(i, i, 1, n, s);
    cout << count << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int syu(int *p, int n) {
  int s = 0;
  for (int i = 0; i < n; i++)
    s += p[i];
  return s;
}
int main() {
  int n, s;
  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    int p[n], count = 0;
    for (int a = 0; a <= 9; a++) {
      p[0] = a;
      if (n == 1 && syu(p, n) == s) {
        count++;
        continue;
      }
      for (int b = a + 1; b <= 9; b++) {
        p[1] = b;
        if (n == 2 && syu(p, n) == s) {
          count++;
          continue;
        }
        for (int c = b + 1; c <= 9; c++) {
          p[2] = c;
          if (n == 3 && syu(p, n) == s) {
            count++;
            continue;
          }
          for (int d = c + 1; d <= 9; d++) {
            p[3] = d;
            if (n == 4 && syu(p, n) == s) {
              count++;
              continue;
            }
            for (int e = d + 1; e <= 9; e++) {
              p[4] = e;
              if (n == 5 && syu(p, n) == s) {
                count++;
                continue;
              }
              for (int f = e + 1; f <= 9; f++) {
                p[5] = f;
                if (n == 6 && syu(p, n) == s) {
                  count++;
                  continue;
                }
                for (int g = f + 1; g <= 9; g++) {
                  p[6] = g;
                  if (n == 7 && syu(p, n) == s) {
                    count++;
                    continue;
                  }
                  for (int h = g + 1; h <= 9; h++) {
                    p[7] = h;
                    if (n == 8 && syu(p, n) == s) {
                      count++;
                      continue;
                    }
                    for (int i = h + 1; i <= 9; i++) {
                      p[8] = i;
                      if (n == 9 && syu(p, n) == s) {
                        count++;
                        continue;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;
// int dp[10][45][10];

int dpc(int n, int s, int num) {
  //  if(dp[n][s][num]!=-1)
  //  return dp[n][s][num];
  if (n == 0)
    return 0;
  if (s == num && n == 1)
    return 1;
  if (num == 9)
    return 0;
  int sum = 0;
  if (n - 1 >= 0 && s - num >= 0)
    sum += dpc(n - 1, s - num, num + 1);
  sum += dpc(n, s, num + 1);
  //  dp[n][s][num]=sum;
  //  cout<<"sum="<<sum<<endl;
  return sum;
}

int main() {
  int n, s;
  for (; cin >> n >> s, n;) {
    /*
    for(int i=0;i<10;i++)
      for(int j=0;j<45;j++)
        for(int x=0;x<10;x++)
        dp[i][j][x]=-1;*/
    cout << dpc(n, s, 0) << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;
int dp[10][45][10];

int dpc(int n, int s, int num) {
  if (dp[n][s][num] != -1)
    return dp[n][s][num];
  if (n == 0)
    return 0;
  if (s == num && n == 1)
    return 1;
  if (num == 9)
    return 0;
  int sum = 0;
  if (n - 1 >= 0 && s - num >= 0)
    sum += dpc(n - 1, s - num, num + 1);
  sum += dpc(n, s, num + 1);
  dp[n][s][num] = sum;
  //  cout<<"sum="<<sum<<endl;
  return sum;
}

int main() {
  int n, s;
  for (; cin >> n >> s, n;) {
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 45; j++)
        for (int x = 0; x < 10; x++)
          dp[i][j][x] = -1;
    cout << dpc(n, s, 0) << endl;
  }
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int n, s;
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    int c = 0;
    for (int i = 0; i < 1 << 10; i++) {
      int tn = 0;
      int ts = 0;
      for (int j = 0; j < 10; j++)
        if (i >> j & 1)
          tn++, ts += j;
      if (tn == n && ts == s)
        c++;
    }
    cout << c << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

// map<pair<pair<int,int>,int>,int> memo;
int memo[256][256][256];

int BT(int N, int S, int d, int p, int s) {
  if (d == N)
    return s == S ? 1 : 0;
  if (s + (N - d) * p > S)
    return 0;

  if (memo[d][p][s] >= 0)
    return memo[d][p][s];
  int ans = 0;
  for (int i = p; i <= S; i++)
    ans += BT(N, S, d + 1, i + 1, s + i);
  return memo[d][p][s] = ans;
}

int main() {
  while (true) {
    for (int i = 0; i < 256 * 256 * 256; i++)
      memo[0][0][i] = -1;

    int n, s;
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;

    cout << BT(n, s, 0, 0, 0) << endl;
  }

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

#include <iostream>
#include <vector>

using namespace std;

int main() {
  unsigned n, s;

  while (cin >> n >> s, (n != 0 || s != 0)) {
    vector<unsigned> no(9);
    unsigned cnt = 0, sum = 0, i, k, max = 0, min = 0;
    for (i = 0; i < n; i++) {
      no[i] = i;
      min += i;
      max += 9 - i;
    }
    if (max < s || min > s) {
      cout << 0 << endl;
      continue;
    }
    cnt = 0;
    while (1) {
      // for(i = 0; i < n; i++) cout << i << no[i] << "  ";
      // cout << endl;
      for (k = sum = 0; k < n; k++) {
        sum += no[k];
      }
      if (sum == s)
        cnt++;
      // cout << sum << endl;
      if (sum >= s)
        no[n - 1] = 9;
      no[n - 1]++;

      for (k = n - 1; k > 0; k--) {
        if (no[k] > 9 - n + k + 1) {
          no[k - 1]++;
          for (i = k; i < n; i++) {
            no[i] = no[i - 1] + 1;
          }
        }
      }
      if (no[0] > 9 - n + 1)
        break;
    }
    cout << cnt << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int Judge(vector<int> no, int n);

int main() {
  int n, s, cnt, sum, i, j, k, judge;

  while (cin >> n >> s, (n != 0 || s != 0)) {
    vector<int> no(9);
    for (i = 0; i < n; i++)
      no[i] = i;
    cnt = 0;
    while (1) {
      if (no[0] == 10)
        break;
      judge = Judge(no, n);
      if (judge == true) {
        for (k = sum = 0; k < n; k++) {
          sum += no[k];
        }
        if (sum == s)
          cnt++;
      }
      no[n - 1]++;
      for (k = n - 1; k > 0; k--) {
        if (no[k] == 10) {
          no[k] = 0;
          no[k - 1]++;
        }
      }
    }
    cout << cnt << endl;
  }
}

int Judge(vector<int> no, int n) {
  int i, j;
  for (i = 0; i + 1 < n; i++) {
    if (no[i] > no[i + 1])
      return false;
    for (j = i + 1; j < n; j++)
      if (no[i] == no[j])
        return false;
  }
  return true;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int sp(int num, int s, int n) {
  if (!num & !s)
    return 1;
  if (n > 9)
    return 0;
  return sp(num - 1, s - n, n + 1) + sp(num, s, n + 1);
}
int main() {
  while (1) {
    int n, s;
    cin >> n >> s;
    if (!n)
      return 0;
    cout << sp(n, s, 0) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int n, s, spn;
void sp(int ne, int ns, bool *flag) {
  if (ne == n & ns == s)
    spn++;
  for (int i = 0; i < 10; ++i) {
    if (flag[i])
      flag[i] = false;
    if (ns == s | ne >= n)
      continue;
    sp(ne + 1, ns + i, flag);
  }
}
int main() {
  while (1) {
    cin >> n >> s;
    if (!n)
      return 0;
    spn = 0;
    bool flag[10] = {true};
    sp(0, 0, flag);
    spn /= (n * (n - 1));
    cout << spn << endl;
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

#define rep(i, j) for (int i = 0; i < (j); i++)
#define reps(i, j, k) for (int i = j; i <= k; i++)
#define in(i, j, k) ((i) >= (j) && (i) <= (k))

int main() {
  int n, s, a, c;
  vector<int> v;
  for (;;) {
    scanf("%d%d", &n, &s);
    if (n == 0 && s == 0)
      break;
    v.clear();
    rep(i, 10) v.push_back(i < n);
    c = 0;
    do {
      a = 0;
      rep(i, 10) a += i * v[i];
      c += (s == a);
    } while (prev_permutation(v.begin(), v.end()));
    printf("%d\\n", c);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

#define rep(i, j) for (int i = 0; i < (j); i++)
#define reps(i, j, k) for (int i = j; i <= k; i++)
#define in(i, j, k) ((i) >= (j) && (i) <= (k))

int main() {
  int n, s, l, a, c;
  for (;;) {
    scanf("%d%d", &n, &s);
    if (n == 0 && s == 0)
      break;
    l = min(10, s);
    vector<int> v(l, 0);
    rep(i, n) v[i] = 1;
    c = 0;
    do {
      a = 0;
      rep(i, l) a += i * v[i];
      c += s == a;
    } while (prev_permutation(v.begin(), v.end()));
    printf("%d\\n", c);
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int bit_count(const int n) {
  int cnt = 0;
  for (int i = 0; i < 10; i++) {
    if (n & 1 << i)
      cnt++;
  }
  return cnt;
}

int main(void) {
  int n, s;
  while (cin >> n >> s) {
    if (n == 0 && s == 0)
      break;
    int answer = 0;
    for (int i = 0; i < 1 << 10; i++) {
      if (bit_count(i) == n) {
        int sum = 0;
        for (int j = 0; j < 10; j++) {
          if (i & 1 << j) {
            sum += j;
          }
        }
        if (sum == s) {
          answer++;
        }
      }
    }
    cout << answer << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  while (1) {
    int n, s;
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;

    vector<int> numbers;
    for (int i = 0; i < s; i++)
      numbers.push_back(i);

    int kotae = 0;
    do {
      bool continue_flag = false;
      for (int i = 0; i < n - 1; i++) {
        if (numbers[i] > numbers[i + 1]) {
          continue_flag = true;
          break;
        }
      }
      if (continue_flag)
        continue;
      int sum = 0;
      for (int i = 0; i < n; i++) {
        sum += numbers[i];
      }
      if (sum == s) {
        kotae++;
      }
    } while (next_permutation(numbers.begin(), numbers.end()));

    kotae /= 6;
    cout << kotae << endl;
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

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

int dp[20][55][20];

int cnt_sum(int n, int s, int x) {
  if (n < 0 || s < 0) {
    return 0;
  }
  if (dp[n][s][x] != -1) {
    return dp[n][s][x];
  }
  if (n == 0 && s == 0) {
    return (1);
  }
  if (x > 9) {
    return (0);
  }

  return dp[n][s][x] = (cnt_sum(n - 1, s - x, x + 1) + cnt_sum(n, s, x + 1));
}
int main() {
  int n, s;
  memset(dp, -1, sizeof(dp));
  while (1) {
    scanf("%d %d", &n, &s);
    if (n == 0 && s == 0) {
      break;
    }
    if (n >= 11 || s >= 46)
      printf("0\\n");
    else
      printf("%d\\n", cnt_sum(n, s, 0));
  }
  return 0;
}

Error: WA

Fixed submission:

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

int dp[20][55][20];

int cnt_sum(int n, int s, int x) {
  if (dp[n][s][x] != -1) {
    return dp[n][s][x];
  }
  if (n == 0 && s == 0) {
    return (1);
  }
  if (x > 9) {
    return (0);
  }

  return dp[n][s][x] = (cnt_sum(n - 1, s - x, x + 1) + cnt_sum(n, s, x + 1));
}
int main() {
  int n, s;
  memset(dp, -1, sizeof(dp));
  while (1) {
    scanf("%d %d", &n, &s);
    if (n == 0 && s == 0) {
      break;
    }
    if (n >= 11 || s >= 46)
      printf("0\\n");
    else
      printf("%d\\n", cnt_sum(n, s, 0));
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

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

int res;
const int d[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

void dfs(int now, int idx, int n, int sum, int s) {
  if (now == n) {
    if (sum == s) {
      res++;
      return;
    }
  }
  if (idx < 10) {
    dfs(now, idx + 1, n, sum, s);
    dfs(now + 1, idx + 1, n, sum + d[idx], s);
  }
}

int main() {
  int n, s;
  queue<int> que;
  while (cin >> n >> s, n || s) {
    res = 0;
    dfs(0, 0, n, 0, s);
    que.push(res);
  }

  while (que.size()) {
    cout << que.front() << endl;
    que.pop();
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int res;
const int d[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

bool dfs(int now, int idx, int n, int sum, int s) {
  if (now == n && sum == s) {
    res++;
    return true;
  }

  if (dfs(now, idx + 1, n, sum, s))
    return true;

  if (dfs(now + 1, idx + 1, n, sum + d[idx], s))
    return true;

  if (idx > 9)
    return false;

  return false;
}

int main() {
  int n, s;

  while (cin >> n >> s, n || s) {
    res = 0;
    dfs(0, 0, n, 0, s);
    cout << res << endl;
  }

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

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int ans;
int n;
int s;

void count_ans(int k, int C, int j) {
  if (k == n) {
    if (C == s) {
      ans++;
    }
  } else {
    for (int i = j + 1; i < 10; i++) {
      count_ans(k + 1, C + i, i);
    }
  }
}

int main() {
  while (cin >> n >> s, (n != 0) || (s != 0)) {
    ans = 0;
    count_ans(0, 0, -1);
    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

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

int n;
int s;
int cc;
vector<int> re;

void test(int xs, int c, int lvl) {
  if (lvl == n && xs == s) {
    cc++;
  } else {
    for (int i = c + 1; i < s; i++) {
      test(xs + i, i, lvl + 1);
    }
  }
}

int main() {
  while (cin >> n >> s, !(n == 0 && s == 0)) {

    cc = 0;
    if (n < s) {
      for (int i = 0; i < n - 1; i++) {
        test(0, i, 1);
      }
    }
    re.push_back(cc);
  }
  for (int i = 0; i < re.size(); i++) {
    cout << re[i] << endl;
  }
}