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

#include <math.h>
#include <stdio.h>

int main(void) {
  int n;
  double v[101][2];
  double s[2];
  int ans;

  while (1) {
    s[0] = 100000;
    scanf("%d", &n);
    if (n == 0)
      break;
    ans = n;

    for (int i = 0; i < n; i++) {
      scanf("%lf,%lf", &v[i][0], &v[i][1]);
      if (s[0] > v[i][0]) {
        s[0] = v[i][0];
        s[1] = v[i][1];
      } else if (s[0] == v[i][0] && s[1] < v[i][1]) {
        s[1] = v[i][1];
      }
    }

    double t[2];
    t[0] = s[0];
    t[1] = s[1];
    double next[2];
    double bias = -M_PI / 2.0;
    double min;
    double theta;
    do {
      min = 2 * M_PI;
      for (int i = 0; i < n; i++) {
        if (v[i][0] == -10000 || v[i][1] == -10000)
          continue;
        if (v[i][0] == t[0] && v[i][1] == t[1])
          continue;
        if (t[0] == v[i][0]) {
          if (t[1] < v[i][1])
            theta = M_PI / 2;
          else if (t[1] > v[i][1])
            theta = -M_PI / 2;
        } else {
          theta = atan((t[1] - v[i][1]) / (t[0] - v[i][0]));
        }
        if (t[0] > v[i][0])
          theta += M_PI;
        if (bias <= theta && min > theta) {
          min = theta;
          next[0] = v[i][0];
          next[1] = v[i][1];
        }
      }
      ans--;
      t[0] = next[0];
      t[1] = next[1];
      bias = min;
      for (int i = 0; i < n; i++) {
        if (v[i][0] == t[0] && v[i][1] == t[1]) {
          v[i][0] = -10000;
          v[i][1] = -10000;
          break;
        }
      }
    } while (t[0] != s[0] || t[1] != s[1]);

    printf("%d\\n", ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>

int main(void) {
  int n;
  double v[101][2];
  double s[2];
  int ans;

  s[0] = 100000;

  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    ans = n;

    for (int i = 0; i < n; i++) {
      scanf("%lf,%lf", &v[i][0], &v[i][1]);
      if (s[0] > v[i][0]) {
        s[0] = v[i][0];
        s[1] = v[i][1];
      }
    }

    double t[2];
    t[0] = s[0];
    t[1] = s[1];
    double next[2];
    double bias = -M_PI / 2.0;
    double min;
    do {
      min = 2 * M_PI;
      for (int i = 0; i < n; i++) {
        if (v[i][0] == -10000 || v[i][1] == -10000)
          continue;
        double theta = atan((t[1] - v[i][1]) / (t[0] - v[i][0]));
        if (t[0] > v[i][0])
          theta += M_PI;
        if (bias <= theta && min > theta) {
          min = theta;
          next[0] = v[i][0];
          next[1] = v[i][1];
        }
      }
      ans--;
      t[0] = next[0];
      t[1] = next[1];
      bias = min;
      for (int i = 0; i < n; i++) {
        if (v[i][0] == t[0] && v[i][1] == t[1]) {
          v[i][0] = -10000;
          v[i][1] = -10000;
          break;
        }
      }
    } while (t[0] != s[0] || t[1] != s[1]);

    printf("%d\\n", ans);
  }

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

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

int main() {
  int n, m, o, d, t, l1, l2;
  string str;
  bool a[30][10], x;

  while (cin >> n && n) {
    cin >> m >> o >> d;
    --m;
    --o;
    for (int i = 0; i < d; i++) {
      cin >> str;
      for (int j = 0; j < n - 1; j++) {
        a[i][j] = str.at(j) - '0';
      }
    }

    l1 = m;
    l2 = o;
    for (int i = d - 1; i >= 0; i--) {
      if (l2 < n - 1 && a[i][l2])
        ++l2;
      else if (l2 && a[i][l2 - 1])
        --l2;
    }
    if (l1 == l2) {
      cout << "0" << endl;
      continue;
    }

    x = false;
    for (int i = 0; i < d; i++) {
      t = 0;
      if (l1 < n - 1 && a[i][l1])
        ++l1;
      else if (l1 && a[i][l1 - 1])
        --l1;
      else
        ++t;
      if (l2 < n - 1 && a[i][l2])
        ++l2;
      else if (l2 && a[i][l2 - 1])
        --l2;
      else
        ++t;
      if (t == 2 && (l1 == l2 + 1 || l2 == l1 + 1)) {
        cout << i + 1 << " " << ((l1 < l2) ? l2 : l1) << endl;
        x = true;
        break;
      }
    }
    if (!x) {
      cout << "1" << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, o, d, t, l1, l2;
  string str;
  bool a[10][30], x;

  while (cin >> n) {
    cin >> m >> o >> d;
    --m;
    --o;
    for (int i = 0; i < d; i++) {
      cin >> str;
      for (int j = 0; j < n - 1; j++) {
        a[i][j] = str.at(j) - '0';
      }
    }
    cin >> t;

    l1 = m;
    l2 = o;
    for (int i = d - 1; i >= 0; i--) {
      if (l2 < n - 1 && a[i][l2])
        ++l2;
      else if (l2 && a[i][l2 - 1])
        --l2;
    }
    if (l1 == l2) {
      cout << "0" << endl;
      continue;
    }

    x = false;
    for (int i = 0; i < d; i++) {
      t = 0;
      if (l1 < n - 1 && a[i][l1])
        ++l1;
      else if (l1 && a[i][l1 - 1])
        --l1;
      else
        ++t;
      if (l2 < n - 1 && a[i][l2])
        ++l2;
      else if (l2 && a[i][l2 - 1])
        --l2;
      else
        ++t;
      if (t == 2 && (l1 == l2 + 1 || l2 == l1 + 1)) {
        cout << i + 1 << " " << ((l1 < l2) ? l2 : l1) << endl;
        x = true;
        break;
      }
    }
    if (!x) {
      cout << "1" << endl;
    }
  }

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

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

int n, m, h, d;
vector<string> F;

bool judge(vector<string> f) {
  int now = m;
  for (int i = 0; i < f.size(); i++) {
    assert(now != 0);
    if (f[i][now - 1] == '1') {
      now = now - 1;
    } else if (f[i][now] == '1') {
      now = now + 1;
    }
    // cout<<F[i]<<" "<<f[i]<<" "<<now<<endl;
  }
  return now == h;
}

pair<int, int> solve() {
  if (judge(F))
    return make_pair(0, 0);
  for (int i = 0; i < F.size(); i++) {
    for (int j = 1; j < F[i].size() - 1; j++) {
      vector<string> tmp = F;
      if (tmp[i][j - 1] != '1' && tmp[i][j + 1] != '1') {
        tmp[i][j] = '1';
        if (judge(tmp)) {
          return make_pair(i + 1, j);
        }
      }
    }
  }
  return make_pair(-1, 0);
}

int main() {
  while (cin >> n, n != 0) {
    cin >> m >> h >> d;
    F.clear();
    for (int i = 0; i < d; i++) {
      string s;
      cin >> s;
      s = "*" + s + "*";
      F.push_back(s);
    }
    pair<int, int> ans = solve();
    if (ans.first == 0) {
      cout << 0 << endl;
    } else if (ans.first == -1) {
      cout << 1 << endl;
    } else {
      cout << ans.first << " " << ans.second << endl;
    }
  }
}

Error: 0

Fixed submission:

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

int n, m, h, d;
vector<string> F;

bool judge(vector<string> f) {
  int now = m;
  for (int i = 0; i < f.size(); i++) {
    assert(now != 0);
    if (f[i][now - 1] == '1') {
      now = now - 1;
    } else if (f[i][now] == '1') {
      now = now + 1;
    }
    // cout<<F[i]<<" "<<f[i]<<" "<<now<<endl;
  }
  return now == h;
}

pair<int, int> solve() {
  if (judge(F))
    return make_pair(0, 0);
  for (int i = 0; i < F.size(); i++) {
    for (int j = 1; j < F.size() - 1; j++) {
      vector<string> tmp = F;
      if (tmp[i][j - 1] != '1' && tmp[i][j + 1] != '1') {
        tmp[i][j] = '1';
        if (judge(tmp)) {
          return make_pair(i + 1, j);
        }
      }
    }
  }
  return make_pair(-1, 0);
}

int main() {
  while (cin >> n, n != 0) {
    cin >> m >> h >> d;
    F.clear();
    for (int i = 0; i < d; i++) {
      string s;
      cin >> s;
      s = "*" + s + "*";
      F.push_back(s);
    }
    pair<int, int> ans = solve();
    if (ans.first == 0) {
      cout << 0 << endl;
    } else if (ans.first == -1) {
      cout << 1 << endl;
    } else {
      cout << ans.first << " " << ans.second << endl;
    }
  }
}
Problem p00069 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

bool Simulation(char line[][15], int start, int goal, int m) {
  int pos = start;

  for (int i = 0; i < m; i++) {
    if (line[i][pos] == '1') {
      pos++;
    } else if (line[i][pos - 1] == '1') {
      pos--;
    }
  }
  return (pos == goal);
}

int main(void) {
  int n, m;
  int start;
  int goal;
  char line[30][15];

  while (1) {
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    scanf("%d", &start);
    scanf("%d", &goal);
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
      scanf("%s", line[i] + 1);
      line[i][0] = '0';
      line[i][n] = '0';
    }

    if (Simulation(line, start, goal, m) == true) {
      puts("0");
      continue;
    }

    bool flag = false;
    for (int i = 0; i < m; i++) {
      for (int j = 1; j < n; j++) {
        if (line[i][j - 1] == '0' && line[i][j + 1] == '0' &&
            line[i][j] == '0') {
          line[i][j] = '1';
          if (Simulation(line, start, goal, m) == true) {
            printf("%d %d\\n", i + 1, j);
            flag = true;
            break;
          }
          line[i][j] = '0';
        }
      }
      if (flag == true) {
        break;
      }
    }

    if (flag == false) {
      puts("1");
    }
  }

  return (0);
}

Error: TLE

Fixed submission:

#include <stdio.h>

bool Simulation(char line[][15], int start, int goal, int m) {
  int pos = start;

  for (int i = 0; i < m; i++) {
    if (line[i][pos] == '1') {
      pos++;
    } else if (line[i][pos - 1] == '1') {
      pos--;
    }
  }
  return (pos == goal);
}

int main(void) {
  int n, m;
  int start;
  int goal;
  char line[30][15];

  while (1) {
    scanf("%d", &n);
    scanf("%d", &start);
    scanf("%d", &goal);
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
      scanf("%s", line[i] + 1);
      line[i][0] = '0';
      line[i][n] = '0';
    }

    if (Simulation(line, start, goal, m) == true) {
      puts("0");
      continue;
    }

    bool flag = false;
    for (int i = 0; i < m; i++) {
      for (int j = 1; j < n; j++) {
        if (line[i][j - 1] == '0' && line[i][j + 1] == '0' &&
            line[i][j] == '0') {
          line[i][j] = '1';
          if (Simulation(line, start, goal, m) == true) {
            printf("%d %d\\n", i + 1, j);
            flag = true;
            break;
          }
          line[i][j] = '0';
        }
      }
      if (flag == true) {
        break;
      }
    }

    if (flag == false) {
      puts("1");
    }
  }

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

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

using namespace std;

int main() {
  while (true) {
    int N;
    cin >> N;
    if (!N)
      break;
    int M, G, D;
    cin >> M >> G >> D;
    vector<string> lots(D);
    for (int i = 0; i < D; ++i) {
      cin >> lots[i];
      lots[i] = '0' + lots[i] + '0';
    }
    vector<vector<int>> history(D + 1, vector<int>(N + 2));
    for (int i = 0; i <= N + 1; ++i)
      history[0][i] = i;

    // Simulation
    for (int turn = 1; turn < D + 1; ++turn) {
      history[turn] = history[turn - 1];
      for (int i = 1; i < N; ++i)
        if (lots[turn - 1][i] == '1')
          swap(history[turn][i], history[turn][i + 1]);
    }
    int target = history[D][G];
    if (target == M)
      cout << 0 << endl;
    else {
      for (int turn = 0; turn < D; ++turn) {
        for (int i = 1; i <= N; ++i) {
          if (history[turn][i] == M) {
            if (history[turn][i - 1] == target &&
                lots[turn].substr(i - 2, 3) == "000") {
              cout << turn + 1 << ' ' << i - 1 << endl;
              goto next;
            } else if (history[turn][i + 1] == target &&
                       lots[turn].substr(i - 1, 3) == "000") {
              cout << turn + 1 << ' ' << i << endl;
              goto next;
            }
          }
        }
      }
      cout << 1 << endl;
    }
  next:;
  }
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  while (true) {
    int N;
    cin >> N;
    if (!N)
      break;
    int M, G, D;
    cin >> M >> G >> D;
    vector<string> lots(D);
    for (int i = 0; i < D; ++i) {
      cin >> lots[i];
      lots[i] = '0' + lots[i] + '0';
    }
    vector<vector<int>> history(D + 1, vector<int>(N + 2));
    for (int i = 0; i <= N + 1; ++i)
      history[0][i] = i;

    // Simulation
    for (int turn = 1; turn < D + 1; ++turn) {
      history[turn] = history[turn - 1];
      for (int i = 1; i < N; ++i)
        if (lots[turn - 1][i] == '1')
          swap(history[turn][i], history[turn][i + 1]);
    }
    int target = history[D][G];
    if (target == M)
      cout << 0 << endl;
    else {
      for (int turn = 0; turn < D; ++turn) {
        for (int i = 1; i <= N; ++i) {
          if (history[turn][i] == M) {
            if (history[turn][i - 1] == target &&
                lots[turn + 1].substr(i - 2, 3) == "000") {
              cout << turn + 1 << ' ' << i - 1 << endl;
              goto next;
            } else if (history[turn][i + 1] == target &&
                       lots[turn + 1].substr(i - 1, 3) == "000") {
              cout << turn + 1 << ' ' << i << endl;
              goto next;
            }
          }
        }
      }
      cout << 1 << endl;
    }
  next:;
  }
  return 0;
}
Problem p00069 (C++) — buggy submission, verdict: Runtime Error

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

int N, M, G, D;

bool c(vector<string> m) {
  int y = M - 1;
  for (int x = 0; x < D; x++) {
    if (y < N - 1 && m[x][y] == '1') {
      y++;
    } else if (0 < y && m[x][y - 1] == '1') {
      y--;
    }
  }
  if (y == G - 1)
    return true;
  else
    return false;
}

bool t(string g) {
  for (int i = 0; i < g.size() - 1; i++) {
    if (g[i] == '1' && g[i + 1] == '1')
      return false;
  }
  return true;
}

int main() {
  while (cin >> N, N) {
    cin >> M >> G >> D;
    vector<string> v(D);
    for (int i = 0; i < D; i++) {
      cin >> v[i];
    }
    if (c(v)) {
      cout << 0 << endl;
      goto escape;
    }
    for (int i = 0; i < D; i++) {
      for (int j = 0; j < N - 1; j++) {
        if (v[i][j] != '1') {
          v[i][j] = '1';
          if (t(v[i])) {
            if (c(v)) {
              cout << i + 1 << " " << j + 1 << endl;
              goto escape;
            };
          }
          v[i][j] = '0';
        }
      }
    }
    cout << 1 << endl;
  escape:;
  }

  return 0;
}

Error: -11

Fixed submission:

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

int N, M, G, D;

bool c(vector<string> m) {
  int y = M - 1;
  for (int x = 0; x < D + 1; x++) {
    if (y < N - 1 && m[x][y] == '1') {
      y++;
    } else if (0 < y && m[x][y - 1] == '1') {
      y--;
    }
  }
  if (y == G - 1)
    return true;
  else
    return false;
}

bool t(string g) {
  for (int i = 0; i < g.size() - 1; i++) {
    if (g[i] == '1' && g[i + 1] == '1')
      return false;
  }
  return true;
}

int main() {
  while (cin >> N, N) {
    cin >> M >> G >> D;
    vector<string> v(D);
    for (int i = 0; i < D; i++) {
      cin >> v[i];
    }
    if (c(v)) {
      cout << 0 << endl;
      goto escape;
    }
    for (int i = 0; i < D; i++) {
      for (int j = 0; j < N - 1; j++) {
        if (v[i][j] != '1') {
          v[i][j] = '1';
          if (t(v[i])) {
            if (c(v)) {
              cout << i + 1 << " " << j + 1 << endl;
              goto escape;
            };
          }
          v[i][j] = '0';
        }
      }
    }
    cout << 1 << endl;
  escape:;
  }

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

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

int n, m, h, d;

int amida(vector<string> t) {
  int now = m;
  rep(i, 0, d) {
    if (t[i][now] == '1')
      now++;
    else if (now >= 1 && t[i][now - 1] == '1')
      now--;
  }
  return now;
}

signed main() {
  while (cin >> n && n) {
    cin >> m >> h >> d;
    m--;
    h--;
    vector<string> s(d + 10), t(d + 10);
    rep(i, 0, d) { cin >> s[i]; }
    bool f = false;
    if (amida(s) == h) {
      cout << 0 << endl;
      f = true;
    } else {
      rep(i, 0, d) {
        rep(j, 0, n - 1) {
          t = s;
          if (t[i][j] == '0') {
            if (j != 0 && t[i][j - 1] == '1')
              continue;
            if (j != n - 2 && t[i][j + 1] == '1')
              continue;
            t[i][j] = '1';
            if (amida(t) == h) {
              f = true;
              cout << i + 1 << " " << j + 1 << endl;
            }
          }
          if (f)
            i = d + 1;
        }
      }
    }
    if (!f)
      cout << 1 << endl;
  }
}

Error: 0

Fixed submission:

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

int n, m, h, d;

int amida(vector<string> t) {
  int now = m;
  rep(i, 0, d) {
    if (t[i][now] == '1')
      now++;
    else if (now >= 1 && t[i][now - 1] == '1')
      now--;
  }
  return now + 1;
}

signed main() {
  while (cin >> n && n) {
    cin >> m >> h >> d;
    m--;
    h;
    vector<string> s(d), t(d);
    rep(i, 0, d) { cin >> s[i]; }
    bool f = false;
    rep(i, 0, d) {
      rep(j, 0, n - 1) {
        t = s;
        if (t[i][j] == '0') {
          if (j != 0 && t[i][j - 1] == '1')
            continue;
          if (j != n - 2 && t[i][j + 1] == '1')
            continue;
          t[i][j] = '1';
          if (amida(t) == h) {
            f = true;
            cout << i + 1 << " " << j + 1 << endl;
          }
        }
        if (f)
          i = d;
      }
    }
    if (!f)
      cout << 1 << endl;
  }
}
Problem p00069 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int d, a[31][12];

bool ok(int s, int g) {
  for (int i = 0; i < d; i++) {
    if (a[i][s - 1] == 1)
      s--;
    else if (a[i][s] == 1)
      s++;
  }
  if (s == g)
    return true;
  return false;
}

int main(void) {

  int n, m, g;
  char in;

  while (cin >> n, n) {

    fill(a[0], a[31], 0);

    cin >> m >> g >> d;

    for (int i = 0; i < d; i++) {
      for (int j = 1; j < n; j++) {
        cin >> in;
        a[i][j] = in - '0';
      }
    }

    if (ok(m, g)) {
      cout << 0 << endl;
      continue;
    }

    bool fg = false;
    int p, q;

    for (int i = 0; i < d; i++) {
      for (int j = 1; j < n; j++) {
        if (a[i][j] == 0 && a[i][j - 1] == 0 && a[i][j + 1] == 0) {
          a[i][j] = 1;
          fg = ok(m, g);
          if (fg) {
            p = i + 1, q = j;
            break;
          }
          a[i][j] = 0;
        }
      }
      if (fg)
        break;
    }
    if (fg)
      cout << p << " " << q << endl;
    else
      cout << 1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int d, a[15][40];

bool ok(int s, int g) {
  for (int i = 0; i < d; i++) {
    if (a[i][s - 1] == 1)
      s--;
    else if (a[i][s] == 1)
      s++;
  }
  if (s == g)
    return true;
  return false;
}

int main(void) {

  int n, m, g;
  char in;

  while (cin >> n, n) {

    fill(a[0], a[15], 0);

    cin >> m >> g >> d;

    for (int i = 0; i < d; i++) {
      for (int j = 1; j < n; j++) {
        cin >> in;
        a[i][j] = in - '0';
      }
    }

    if (ok(m, g)) {
      cout << 0 << endl;
      continue;
    }

    bool fg = false;
    int p, q;

    for (int i = 0; i < d; i++) {
      for (int j = 1; j < n; j++) {
        if (a[i][j] == 0) {
          a[i][j] = 1;
          fg = ok(m, g);
          if (fg)
            p = i + 1, q = j;
          a[i][j] = 0;
        }
      }
      if (fg)
        break;
    }
    if (fg)
      cout << p << " " << q << endl;
    else
      cout << 1 << endl;
  }

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

#include <iostream>
using namespace std;

static int dp[1 << 10][10001] = {};

int main() {
  int n, s;
  while (cin >> n >> s) {
    int res = 0;
    for (int i = 0; i < (1 << 10); i++) {
      for (int j = 0; j <= 10000; j++)
        dp[i][j] = 0;
    }
    dp[0][0] = 1;
    for (int i = 1; i < (1 << 10); i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if ((i >> j) & 1)
          cnt++;
      }
      if (cnt > n)
        continue;
      for (int j = 0; j < 10; j++) {
        if ((i >> j) & 1) {
          for (int k = 0; k <= s; k++) {
            if (k - cnt * j >= 0)
              dp[i][k] += dp[i - (1 << j)][k - cnt * j];
          }
        }
      }
    }
    for (int i = 0; i < (1 << 10); i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++)
        if ((i >> j) & 1)
          cnt++;
      if (cnt == n)
        res += dp[i][s];
    }
    cout << res << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, s;
  while (cin >> n >> s) {
    int dp[1 << 10][10001] = {}, res = 0;
    dp[0][0] = 1;
    for (int i = 1; i < (1 << 10); i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++) {
        if ((i >> j) & 1)
          cnt++;
      }
      if (cnt > n)
        continue;
      for (int j = 0; j < 10; j++) {
        if ((i >> j) & 1) {
          for (int k = 0; k <= s; k++) {
            if (k - cnt * j >= 0)
              dp[i][k] += dp[i - (1 << j)][k - cnt * j];
          }
        }
      }
    }
    for (int i = 0; i < (1 << 10) - 1; i++) {
      int cnt = 0;
      for (int j = 0; j < 10; j++)
        if ((i >> j) & 1)
          cnt++;
      if (cnt == n)
        res += dp[i][s];
    }
    cout << res << endl;
  }
  return 0;
}
Problem p00070 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long ll;

int table
    [11]
    [1000]; // memo[n][s]には最終的にn個の数字を使って和がsのものを何通りで作れるかが入る
int memo[11];

void dfs(int depth, int sum) {
  table[depth - 1][sum]++;
  for (int i = 0; i < 10; i++) {
    if (memo[i] == 0) {
      memo[i] = 1;
      dfs(depth + 1, sum + depth * i);
      memo[i] = 0;
    }
  }
}

int main(void) {
  dfs(1, 0);
  int n, s;
  while (cin >> n >> s) {
    if (n > 10 || s > 330) {
      cout << 0 << endl;
    } else {
      cout << table[n][s] << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define INF 100000000
typedef long long ll;

int memo
    [11]
    [1000]; // memo[n][s]には最終的にn個の数字を使って和がsのものを何通りで作れるかが入る

void dfs(vector<int> used, int now) {
  cout << "dfs:" << used.size() << endl;
  int num = used.size() + 1;
  if (num == 11)
    return;
  for (int i = 0; i < 10; i++) {
    if (find(used.begin(), used.end(), i) == used.end()) {
      int next = now + i * num;
      memo[num][next]++;
      used.push_back(i);
      dfs(used, next);
      used.pop_back();
    }
  }
}

int main(void) {
  vector<int> none;
  dfs(none, 0);
  cout << "dfs end" << endl;
  int n, s;
  while (cin >> n >> s) {
    cout << memo[n][s] << endl;
  }
  return 0;
}