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

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

int n, s, res = 0;

void dfs(int sum, int now, int cnt) {
  if (now == 10) {
    if (sum == s && cnt == n) {
      res++;
    }
    return;
  }
  dfs(sum, now + 1, cnt);
  dfs(sum + now, now + 1, cnt + 1);
  return;
}

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

Error: TLE

Fixed submission:

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

int n, s, res = 0, w = 1;
int a[10] = {0};

void dfs(int sum, int cnt) {
  if (cnt == n) {
    if (sum == s) {
      res++;
      return;
    }
  }
  for (int i = 0; i < 10; i++) {
    if (a[i] == 0) {
      a[i] = 1;
      dfs(sum + i, cnt + 1);
      a[i] = 0;
    }
  }
  return;
}

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

// AOJ Problem0030

#include <iostream>
#include <vector>

using namespace std;

int ans;

void solve(
    int n, int s, int m, int sum,
    int max) { // n:何個か s:目的値 m:何回目か sum:現在の合計 max:最大の足した数

  if (m > n || sum > s) {
    return;
  }

  else if (n == m && sum == s) {
    ans++;
    return;
  }

  else {
    for (int i = max + 1; i <= 9; i++) {

      solve(n, s, m + 1, sum + i, i);
    }
  }
}

int main() {

  int n, s;

  vector<int> dataN;
  vector<int> dataS;

  for (;;) {
    cin >> n;
    cin >> s;
    if (n == 0 && s == 0) {
      break;
    }
    dataN.push_back(n);
    dataS.push_back(s);
  }
  for (int j = 0; j < dataN.size(); j++) {

    ans = 0;

    for (int i = 0; i <= 9; i++) {
      solve(dataN[j], dataS[j], 1, i, i);
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

// AOJ Problem0030

#include <iostream>
#include <vector>

using namespace std;

int ans;

void solve(
    int n, int s, int m, int sum,
    int max) { // n:何個か s:目的値 m:何回目か sum:現在の合計 max:最大の足した数

  if (m > n || sum > s) {
    return;
  }

  else if (n == m && sum == s) {
    ans++;
    return;
  }

  else {
    for (int i = max + 1; i <= s; i++) {

      solve(n, s, m + 1, sum + i, i);
    }
  }
}

int main() {

  int n, s;

  vector<int> dataN;
  vector<int> dataS;

  for (;;) {
    cin >> n;
    cin >> s;
    if (n == 0 && s == 0) {
      break;
    }
    dataN.push_back(n);
    dataS.push_back(s);
  }
  for (int j = 0; j < dataN.size(); j++) {

    ans = 0;

    for (int i = 0; i <= dataS[j]; i++) {
      solve(dataN[j], dataS[j], 1, i, i);
    }

    cout << ans << endl;
  }

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

#include <iostream>

using namespace std;

/** Application main entry point. */
int main(int argc, char *argv[]) {
  int table[11][50] = {};

  for (int i = 0; i < 0x400; ++i) /* 0x400: (10000000000)_2 (10 zeros) */
  {
    int sum = 0;
    int ctr = 0;
    int cur = -1;

    while (true) {
      int __tmp = i >> ++cur;

      if (!__tmp)
        break;
      if (__tmp & 1) {
        sum += cur;
        ++ctr;
      }
    }

    table[ctr][sum]++;
  }

  while (true) {
    int n, s;

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

    cout << (n >= 0 && n <= 10 && s >= 0 && s < 50 ? table[n][s] : 0) << endl;
  }

  return (0);
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <iostream>

using namespace std;

/** Application main entry point. */
int main(int argc, char *argv[]) {
  int table[11][50] = {};

  for (int i = 0; i < 0x800; ++i) /* 0x800: (10000000000)_2 (10 zeros) */
  {
    int sum = 0;
    int ctr = 0;
    int cur = -1;

    while (true) {
      int __tmp = i >> ++cur;

      if (!__tmp)
        break;
      if (__tmp & 1) {
        sum += cur;
        ++ctr;
      }
    }

    table[ctr][sum]++;
  }

  while (true) {
    int n, s;

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

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

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

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

int n, s;
int used[10];
int ans = 0;

void func(int num, int sum) {
  if (num == n) {
    if (sum == s) {
      ans++;
    }
    return;
  }

  for (int i = used[num]; i <= 9; i++) {
    used[num + 1] = i + 1;
    func(num + 1, sum + i);
    used[num + 1] = 0;
  }
}

int main() {
  while (1) {
    memset(used, 0, 10);
    ans = 0;

    std::cin >> n >> s;
    if (!n && !s)
      break;

    func(0, 0);

    std::cout << ans << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
  double K, L, M, H, N, A[120], B[120], C, D, R;
  int I;
  while (scanf("%lf", &N) && N) {
    for (I = 1; I <= N; I++) {
      scanf("%lf %lf", &A[I], &B[I]);
    }
    scanf("%lf", &R);
    bool Flag = 1;
    /*for(I=1;I<N&&Flag;I++){
          if(B[I]==B[I+1]){
              H=(A[I+1]+A[I])/2;
              K=(A[I]*A[I])-(2*A[I]*H)+(H*H)+(B[I]*B[I])-(R*R);
              K=(2*B[I]*2*B[I])-(4*K);
              K=K+0.000000001;
              if(K<0) Flag=0;
          }
          else{
              C=-(A[I]*A[I])+(A[I+1]*A[I+1])-(B[I]*B[I])+(B[I+1]*B[I+1])/(2*(B[I+1]-B[I]));
              D=(A[I+1]-A[I])/(B[I+1]-B[I]);
              M=(A[I]*A[I])+(B[I]*B[I])-(2*B[I]*C)+(C*C)-(R*R);
              L=(2*B[I]*D)-(2*A[I])-(2*C*D);
              H=(L*L)-(4*((D*D)+1)*M);
              printf("%lf\\n",H);
              H=H+0.000000001;
              //||(D*D+1)==0
              if(H<0||(D*D+1)==0) Flag=0;
          }
      }*/
    if (B[I] == B[I + 1]) {
      H = (A[I + 1] + A[I]) / 2;
      K = (A[I] * A[I]) - (2 * A[I] * H) + (H * H) + (B[I] * B[I]) - (R * R);
      K = ((2 * B[I] * 2 * B[I]) - (4 * K));
      K = K + 0.000000001;
      if (K < 0)
        Flag = 0;
      else {
        K = sqrt(K);
        K = (2 * B[I] + K) / 2;
      }
    } else {
      C = -(A[I] * A[I]) + (A[I + 1] * A[I + 1]) - (B[I] * B[I]) +
          (B[I + 1] * B[I + 1]) / (2 * (B[I + 1] - B[I]));
      D = (A[I + 1] - A[I]) / (B[I + 1] - B[I]);
      M = (A[I] * A[I]) + (B[I] * B[I]) - (2 * B[I] * C) + (C * C) - (R * R);
      L = (2 * B[I] * D) - (2 * A[I]) - (2 * C * D);
      H = ((L * L) - (4 * ((D * D) + 1) * M));
      printf("%lf\\n", H);
      H = H + 0.000000001;
      //||(D*D+1)==0
      if (H < 0 || (D * D + 1) == 0)
        Flag = 0;
      else {
        H = sqrt(H);
        H = (-1 * (L) + H) / (2 * (D * D + 1));
        K = C - (H * D);
      }
    }
    for (I = 1; I < N && Flag; I++) {
      M = (A[I] - H) * (A[I] - H) + (B[I] - K) * (B[I] - K);
      L = R * R;
      if (M > L)
        Flag = 0;
    }
    if (Flag)
      printf("The polygon can be packed in the circle.\\n");
    else
      printf("There is no way of packing that polygon.\\n");
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;
int 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, 9);
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
int a;
int f(int n, int s, int i) {
  if (n == 1 && i >= s && s >= 0) {
    a++;
    return 0;
  }
  if (s <= 0)
    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, 9);
    cout << a << endl;
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int n, s;

int recursion(int sum, int num, int cnt) {
  if (sum > s || cnt > n)
    return 0;
  if (cnt == n && sum == s)
    return 1;
  if (num > 9)
    return 0;
  int hoge = 0;
  hoge += recursion(sum + num, num + 1, cnt + 1);
  hoge += recursion(sum, num + 1, cnt);
  return hoge;
}

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n, s;

int recursion(int sum, int num, int cnt) {
  if (sum > s || cnt > n)
    return 0;
  if (cnt == n && sum == s)
    return 1;
  if (num > s)
    return 0;
  int hoge = 0;
  hoge += recursion(sum + num, num + 1, cnt + 1);
  hoge += recursion(sum, num + 1, cnt);
  return hoge;
}

int main() {
  while (cin >> n >> s, n || s) {
    cout << recursion(0, 0, 0) << endl;
  }
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int s;

void com(int c, int p[100], int a, int b) {
  if (c == a) {
    int m = 0;
    for (int i = 1; i <= a; i++)
      m += p[i];
    if (b == m)
      s++;
  } else {
    for (int i = p[c] + 1; i <= min(9, b - p[c]); i++) {
      p[c + 1] = i;
      com(c + 1, p, a, b);
    }
  }
}

int main() {
  int a, b;
  while (1) {
    cin >> a >> b;
    if (a + b == 0)
      break;
    s = 0;
    int p[100];
    p[0] = -1;
    com(0, p, a, b);
    cout << s << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int s;

void com(int c, int p[100], int a, int b) {
  if (c == a) {
    int m = 0;
    for (int i = 1; i <= a; i++)
      m += p[i];
    if (m == b)
      s++;
  } else {
    for (int i = p[c] + 1; i <= b - p[c]; i++) {
      p[c + 1] = i;
      com(c + 1, p, a, b);
    }
  }
}

int main() {
  int a, b;
  while (1) {
    cin >> a >> b;
    if (a + b == 0)
      break;
    s = 0;
    int p[100];
    p[0] = -1;
    com(0, p, a, b);
    cout << s << endl;
  }
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

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

  int res = 0;
  for (int i = k + 1; i < 10; i++) {
    res += cnt_sum_s(n - 1, i, s, tmp_sum + i);
  }

  return res;
}

int main() {
  // ifstream cin("../test.txt");
  while (true) {
    int n, s;
    cin >> n >> s;
    if (!(n | s))
      break;

    int res = cnt_sum_s(n, -1, s, 0);

    cout << res << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

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

  int res = 0;
  for (int i = k + 1; i < 10; i++) {
    res += cnt_sum_s(n - 1, i, s, tmp_sum + i);
  }

  return res;
}

int main() {
  ifstream cin("../test.txt");
  while (true) {
    int n, s;
    cin >> n >> s;
    if (!(n | s))
      break;

    int res = cnt_sum_s(n, -1, s, 0);

    cout << res << endl;
  }
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int t;
int num[10];

void sousa(int a, int b) {
  for (num[a - 1] = num[a] - 1; num[a - 1] >= 0; num[a - 1]--) {
    if (a - 1 < 0 || b < 0) {
      break;
    } else if (a - 1 == 0 && b - num[a - 1] == 0) {
      t++;
      break;
    } else {
      sousa(a - 1, b - num[a - 1]);
    }
  }
}
int main() {
  vector<int> array;
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    if (m > 45) {
      array.push_back(0);
      continue;
    }
    t = 0;
    num[n] = 10;
    sousa(n, m);
    array.push_back(t);
  }
  for (int i = 0; i < array.size(); i++) {
    cout << array[i] << endl;
  }
}

Error: TLE

Fixed submission:

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

int t;
int n[10];

void sousa(int a, int b) {
  for (n[a - 1] = 9; n[a - 1] >= 0; n[a - 1]--) {
    if (a - 1 < 0 || b < 0) {
      cout << "out" << endl;
      break;
    } else if (a - 1 == 0 && b - n[a - 1] == 0) {
      cout << "ok" << endl;
      t++;
      break;
    } else {
      cout << "lasting" << endl;
      sousa(a - 1, b - n[a - 1]);
    }
  }
}
int main() {
  vector<int> array;
  int n, m;
  while (cin >> n >> m) {
    if (n == 0 && m == 0) {
      break;
    }
    if (m > 45) {
      array.push_back(0);
      continue;
    }
    t = 0;
    sousa(n, m);
    array.push_back(t);
  }
  for (int i = 0; i < array.size(); i++) {
    cout << array[i] / 2 << endl;
  }
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1 << 29;
typedef long long ll;
typedef pair<int, int> PI;

int n, s, t, res;

void dfs(int n, int t, int sum) {
  if (n == 0 && sum == s) {
    res++;
    return;
  }
  if (sum > s || n <= 0 || t > s - sum)
    return;
  for (int i = t + 1; i <= 10; ++i) {
    dfs(n - 1, i, sum + i - 1);
  }
}

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1 << 29;
typedef long long ll;
typedef pair<int, int> PI;

int n, s, t, res;

void dfs(int n, int t, int sum) {
  if (n == 0 && sum == s) {
    res++;
    return;
  }
  if (sum > s || n <= 0 || t > s - sum)
    return;
  for (int i = t + 1; i <= s; ++i) {
    dfs(n - 1, i, sum + i - 1);
  }
}

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

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

#include <iostream>
using namespace std;

int n, s;

int dfs(int i, int c, int sum) {
  int res = 0;
  if (n < c || c + 10 - i < n || s < sum)
    return 0;
  if (c == n && sum == s)
    return 1;
  res += dfs(i + 1, c, sum);
  res += dfs(i + 1, c + 1, sum + i);
  return res;
}
int main() {
  while (cin >> n >> s, n || s)
    cout << dfs(0, 0, 0) << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int n, s;

int dfs(int i, int c, int sum) {
  int res = 0;
  if (c + 10 - i < n || s < sum)
    return 0;
  if (c == n && sum == s)
    return 1;
  res += dfs(i + 1, c, sum);
  res += dfs(i + 1, c + 1, sum + i);
  return res;
}
int main() {
  while (cin >> n >> s, n || s)
    cout << dfs(0, 0, 0) << endl;
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

using namespace std;

int mark[10], n, m, ans;

void dfs(int d, int sum, int last) {
  if (d == n) {
    if (sum == m)
      ans++;
    return;
  } else if (sum > m)
    return;
  for (int i = last; i < 10; i++) {
    dfs(d + 1, sum + i, i + 1);
  }
}
int main() {
  while (1) {
    cin >> n >> m;
    if (n == m && n == 0)
      return 0;
    ans = 0;
    dfs(0, 0, 0);
    cout << ans << endl;
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int N = 12;
int n, s;
int ans = 0;
typedef pair<int, int> pii;
map<pii, int> m;

int suma(int a) {
  int tot = s * (s + 1) / 2;
  return tot - a * (a + 1) / 2;
}

void bt(int sum, int index, int pos) {
  if (sum == 0 && pos == n) {
    ans++;
    return;
  }
  if (pos == n)
    return;
  if (sum < 0)
    return;
  for (int i = index; i <= min(9, s); i++) {
    bt(sum - i, i + 1, pos + 1);
  }
}

int main() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  while (true) {
    cin >> n >> s;
    if (!n && !s)
      return 0;
    pii p = make_pair(n, s);
    if (!m.count(p)) {
      bt(s, 0, 0);
      m[p] = ans;
    } else
      ans = m[p];
    cout << ans << "\\n";
    ans = 0;
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

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

int memo[10][1000][20];
// 3,2,1
int dfs(int c, int h, int m) // c:選んだ回数、h:残りの数字、m以下の数字から選ぶ
{
  if (c == 0 && h == 0)
    return 1;
  if (h < 0 || m < 0 || c < 0)
    return 0;
  /*if(memo[c][h][m] != -1)
          return memo[c][h][m];*/
  int res = 0;
  for (int i = 0; i <= m; ++i) {
    res += dfs(c - 1, h - i, i - 1);
  }
  // memo[c][h][m] = res;
  return res;
}

int main(void) {
  while (1) {
    int n, s;
    cin >> n >> s;
    if (n == 0 && s == 0)
      return 0;
    memset(memo, -1, sizeof(memo));
    cout << dfs(n, s, 9) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int memo[10][1000][20];
// 3,2,1
int dfs(int c, int h, int m) // c:選んだ回数、h:残りの数字、m以下の数字から選ぶ
{
  if (c == 0 && h == 0)
    return 1;
  if (h < 0 || m < 0 || c < 0)
    return 0;
  if (memo[c][h][m] != -1)
    return memo[c][h][m];
  int res = 0;
  for (int i = 0; i <= m; ++i) {
    res += dfs(c - 1, h - i, i - 1);
  }
  memo[c][h][m] = res;
  return res;
}

int main(void) {
  while (1) {
    int n, s;
    cin >> n >> s;
    if (n == 0 && s == 0)
      return 0;
    memset(memo, -1, sizeof(memo));
    cout << dfs(n, s, 9) << endl;
  }
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int n, s;
int c = 0;
int i = 0;
int j = 0;
int q = 0;
int sum = 0;
int date[15] = {0};

int sub(int start, int n, int x) {
  if (x == n) {
    for (int i = 0; i < n; i++) {

      sum += date[i];
    }
    if (sum == s) {
      q++;
    }
    sum = 0;
    return 0;
  }

  for (int i = start; i < 10; i++) {

    date[x] = i;

    sub(i + 1, n, x + 1);
  }
}

int main() {

  n = 0;
  while (true) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    sub(0, n, 0);

    cout << q << endl;
    q = 0;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int n, s;
int c = 0;
int i = 0;
int j = 0;
int q = 0;
int date[15] = {0};

int sub(int start, int n, int x) {
  if (x == n) {
    for (int i = 0; i < n; i++) {
      j = i - 1;
      /*cout << date[i];*/
      if (j > 0) {
        date[i] += date[j];
      }
      if (i == n - 1 && date[i] == s) {
        q++;
      }
    }
    return 0;
  }

  for (int i = start; i < 10; i++) {

    date[x] = i;

    sub(i + 1, n, x + 1);
  }
}

int main() {

  n = 0;
  while (true) {
    cin >> n >> s;
    sub(0, n, 0);

    cout << q << endl;
    q = 0;
  }
}
Problem p00030 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int n, s, *num, pattern;
void search(int th) {
  if (th == n) {
    int sum = 0;
    for (int i = 0; i < n; i++)
      sum += num[i];
    if (s == sum) {
      for (int j = 0; j + 1 < n; j++)
        if (num[j] >= num[j + 1])
          return;
      /*
      for (int j = 0; j < n; j++)
        cout << num[j];
      cout << endl;
      */
      pattern++;
    }
  } else {
    int start = 0;
    if (th > 0)
      start = num[th - 1] + 1;
    for (int i = start; i < 10; i++) {
      num[th] = i;
      search(th + 1);
    }
  }
}

int main(int argc, char *argv[]) {
  vector<int> result;
  while (true) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    num = new int[n];
    memset(num, 0, sizeof(int) * n);

    pattern = 0;
    search(0);
    result.push_back(pattern);
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int n, s, *num, pattern;
void search(int th) {
  if (th == n) {
    int sum = 0;
    for (int i = 0; i < n; i++)
      sum += num[i];
    if (s == sum) {
      for (int j = 0; j + 1 < n; j++)
        if (num[j] >= num[j + 1])
          return;
      /*
      for (int j = 0; j < n; j++)
        cout << num[j];
      cout << endl;
      */
      pattern++;
    }
  } else {
    for (int i = 0; i < 10; i++) {
      num[th] = i;
      search(th + 1);
    }
  }
}

int main(int argc, char *argv[]) {
  vector<int> result;
  while (true) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    num = new int[n];
    memset(num, 0, sizeof(int) * n);

    pattern = 0;
    search(0);
    result.push_back(pattern);
  }

  for (int i = 0; i < result.size(); i++)
    cout << result[i] << endl;
  return 0;
}
Problem p00030 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int A[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int cunt = 0;

void depth(int n, int s, int i) {

  if (n == 0 && s == 0) {
    cunt++;
    return;
  } else if (n == 0)
    return;
  else if (s < 0)
    return;
  else if (i == 10)
    return;

  depth(n - 1, s - A[i], i + 1);
  depth(n, s, i + 1);
}

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

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int A[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int cunt = 0;

void depth(int n, int s, int i) {

  if (n == 0 && s == 0) {
    cunt++;
    return;
  } else if (n == 0)
    return;
  else if (s < 0)
    return;
  else if (i == 10)
    return;

  depth(n - 1, s - A[i], ++i);
  depth(n, s, ++i);
}

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

#include <cstdint>
#include <iostream>

std::uint32_t some_of_integer(std::uint32_t n, std::uint32_t s,
                              std::uint32_t sum = 0, std::uint32_t i = 0) {
  std::uint32_t num_cmb = 0;
  if (n == 0) {
    if (sum + i <= s && s <= sum + 9) {
      ++num_cmb;
    }
  } else {
    for (; i < 9; ++i) {
      num_cmb += some_of_integer(n - 1, s, sum + i, i + 1);
    }
  }
  return num_cmb;
}

int main() {
  std::uint32_t n, s;
  for (std::cin >> n >> s; !(n == 0 && s == 0); std::cin >> n >> s) {
    std::cout << some_of_integer(n - 1, s) << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdint>
#include <iostream>

std::uint16_t some_of_integer(std::uint16_t n, std::uint16_t s,
                              std::uint16_t sum = 0, std::uint16_t i = 0) {
  std::uint16_t num_cmb = 0;
  if (n == 0) {
    if (sum + i <= s && s <= sum + 9) {
      ++num_cmb;
    }
  } else {
    for (; i < 9; ++i) {
      num_cmb += some_of_integer(n - 1, s, sum + i, i + 1);
    }
  }
  return num_cmb;
}

int main() {
  std::uint16_t n, s;
  for (std::cin >> n >> s; !(n == 0 && s == 0); std::cin >> n >> s) {
    std::cout << some_of_integer(n - 1, s) << std::endl;
  }

  return 0;
}