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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep(i, n) REP(i, 0, (n))
#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define all(r) r.begin(), r.end()
#define fi first
#define se second
#define println(X) cout << X << endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int dp[11][400][(1 << 10)];

int main() {
  int n, s;
  while (cin >> n >> s) {
    if (s > 385 || n > 10) {
      cout << 0 << endl;
      continue;
    }
    for (int i = 0; i < 11; i++) {
      for (int j = 0; j < 400; j++) {
        for (int k = 0; k < (1 << 10); k++) {
          dp[i][j][k] = -1;
        }
      }
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 400; j++) {
        for (int k = 0; k < 10; k++) {
          for (int l = 0; l < 1 << 10; l++) {
            if (j + k * i >= 400 || dp[i - 1][j][l] < 0 || (l & 1 << k))
              continue;
            dp[i][j + k * i][l | 1 << k] = max(0, dp[i][j + k * i][l | 1 << k]);
            dp[i][j + k * i][l | 1 << k] += dp[i - 1][j][l];
          }
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < 1 << 10; i++) {
      ans += max(0, dp[n][s][i]);
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep(i, n) REP(i, 0, (n))
#define pb(n) push_back(n)
#define mp(n, m) make_pair(n, m)
#define all(r) r.begin(), r.end()
#define fi first
#define se second
#define println(X) cout << X << endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;

int dp[10][400][(1 << 10)];

int main() {
  int n, s;
  while (cin >> n >> s) {
    if (s > 385 || n > 10) {
      cout << 0 << endl;
      continue;
    }
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 400; j++) {
        for (int k = 0; k < (1 << 10); k++) {
          dp[i][j][k] = -1;
        }
      }
    }
    dp[0][0][0] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 400; j++) {
        for (int k = 0; k < 10; k++) {
          for (int l = 0; l < 1 << 10; l++) {
            if (j + k * i >= 400 || dp[i - 1][j][l] < 0 || (l & 1 << k))
              continue;
            dp[i][j + k * i][l | 1 << k] = max(0, dp[i][j + k * i][l | 1 << k]);
            dp[i][j + k * i][l | 1 << k] += dp[i - 1][j][l];
          }
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < 1 << 10; i++) {
      ans += max(0, dp[n][s][i]);
    }
    cout << ans << endl;
  }
}