Problem p00070 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o)                                                                \\
  { cerr << #o << " " << o << endl; }
#define dumpc(o)                                                               \\
  {                                                                            \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

static int dp[11][1 << 10][331];
int n, s;
int dfs(int m, int state, int sum) {
  if (sum < 0 || m < 0 || sum > 330)
    return 0;
  if (dp[m][state][sum] != -1)
    return dp[m][state][sum];
  dp[m][state][sum] = 0;
  rep(i, 0, 10) {
    if (((1 << i) & state) != 0)
      dp[m][state][sum] += dfs(m - 1, state - (1 << i), sum - m * i);
  }
  // if (dp[m][state][sum] != 0)cerr << m << " " << state << " " << sum << " "
  // << dp[m][state][sum] << endl;
  return dp[m][state][sum];
}

signed main() {
  fill(dp[0][0], dp[11][0], -1);
  dp[0][0][0] = 1;
  for (; cin >> n >> s;) {
    int sum = 0;
    // rep(i, 0, 11) {
    //	dump(dfs(i, (1 << i) - 1, (sum += i*(i - 1)))); cerr << i << " " << ((1
    //<< i) - 1) << " " << sum << endl;
    // }
    // dump(dfs(1, 0, 0));
    // dump(dfs(1, 0, 0));
    int ans = 0;
    rep(state, 0, 1 << 10) ans += dfs(n, state, s);
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o)                                                                \\
  { cerr << #o << " " << o << endl; }
#define dumpc(o)                                                               \\
  {                                                                            \\
    cerr << #o;                                                                \\
    for (auto &e : (o))                                                        \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

static int dp[10][1 << 10][340];
int n, s;
int dfs(int m, int state, int sum) {
  if (sum < 0 || m < 0 || sum > 330)
    return 0;
  if (dp[m][state][sum] != -1)
    return dp[m][state][sum];
  dp[m][state][sum] = 0;
  rep(i, 0, 10) {
    if (((1 << i) & state) != 0)
      dp[m][state][sum] += dfs(m - 1, state - (1 << i), sum - m * i);
  }
  // if (dp[m][state][sum] != 0)cerr << m << " " << state << " " << sum << " "
  // << dp[m][state][sum] << endl;
  return dp[m][state][sum];
}

signed main() {
  fill(dp[0][0], dp[10][0], -1);
  dp[0][0][0] = 1;
  for (; cin >> n >> s;) {
    int ans = 0;
    rep(state, 0, 1 << 10) ans += dfs(n, state, s);
    cout << ans << endl;
  }
  return 0;
}