Problem p04015 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = (b)-1; i >= (a); i--)
#define REP(i, n) for (auto i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = (n)-1; i >= 0; i--)
#define EACH(i, v) for (auto &i : v)
#define inf INT_MAX / 3
#define INF INT_MAX / 3
#define eps 1e-15
#define EPS 1e-15
#define TEN9 1000000000
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SET(a, c) memset(a, c, sizeof a)
#define CLR(a) memset(a, 0, sizeof a)
#define pii pair<int, int>
#define pcc pair<char, char>
#define pic pair<int, char>
#define pci pair<char, int>
#define mii map<int, int>
#define msd map<string, double>
#define msi map<string, int>
#define ti3 tuple<int, int, int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout << #x << ": " << x << endl
#define DEBUG(x) cout << #x << ": " << x << endl
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define pi 2 * acos(0.0)
#define INFILE() freopen("in0.txt", "r", stdin)
#define OUTFILE() freopen("out0.txt", "w", stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define FST first
#define SEC second
#define SORT(v) sort(ALL(v));
#define VVI(v, n1, n2) vector<vector<int>> v(n1, vector<int>(n2, 0));
#define int(x)                                                                 \
  int x;                                                                       \
  scanf("%d", &x);
#define lint(x)                                                                \
  long long x;                                                                 \
  scanf("%lld", &x);
#define vint(v, n)                                                             \
  vector<int> v(n);                                                            \
  REP(i, n) scanf("%d", &v[i]);
#define vvint(v, n1, n2)                                                       \
  vector<vector<int>> v(n1, vector<int>(n2, 0));                               \
  REP(i, n1) REP(j, n1) scanf("%d", &v[i][j]);
#define vlint(v, n)                                                            \
  vector<ll int> v(n);                                                         \
  REP(i, n) scanf("%lld", &v[i]);
#define vvlint(v, n1, n2)                                                      \
  vector<vector<ll int>> v(n1, vector<ll int>(n2, 0));                         \
  REP(i, n1) REP(j, n1) scanf("%lld", &v[i][j]);
#define double(x)                                                              \
  double x;                                                                    \
  scanf("%lf", &x);
#define vdouble(v, n)                                                          \
  vector<double> v(n);                                                         \
  REP(i, n) scanf("%lf", &v[i]);
#define vvdoube(v, n1, n2)                                                     \
  vector<vector<double>> v(n1, vector<double>(n2, 0));                         \
  REP(i, n1) REP(j, n1) scanf("%lf", &v[i][j]);
#define char(x)                                                                \
  char x;                                                                      \
  scanf("%c", &x);
#define vchar(v, n)                                                            \
  vector<char> v(n);                                                           \
  REP(i, n) scanf("%c", &v[i]);
#define vvchar(v, n1, n2)                                                      \
  vector<vector<char>> v(n1, vector<char>(n2, 0));                             \
  REP(i, n1) REP(j, n1) scanf("%c", &v[i][j]);
#define string(x)                                                              \
  string x;                                                                    \
  cin >> x;
#define vstring(v, n)                                                          \
  vector<string> v(n);                                                         \
  REP(i, n) cin >> v(i);

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]));

ll int dp[50][50][2501] = {0};

int main() {

  int(N) int(A) vint(v, N) dp[0][0][0] = 1;
  FOR(j, 0, N) {
    FOR(k, 0, N + 1) {
      REP(l, A * N + 1) {
        dp[j + 1][k][l] += dp[j][k][l];
        dp[j + 1][k + 1][l + v[j]] += dp[j][k][l];
      }
    }
  }
  ll int ans = 0;
  FOR(k, 1, N + 1) { ans += dp[N][k][k * A]; }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (auto i = (b)-1; i >= (a); i--)
#define REP(i, n) for (auto i = 0; i < (n); i++)
#define RREP(i, n) for (auto i = (n)-1; i >= 0; i--)
#define EACH(i, v) for (auto &i : v)
#define inf INT_MAX / 3
#define INF INT_MAX / 3
#define eps 1e-15
#define EPS 1e-15
#define TEN9 1000000000
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SET(a, c) memset(a, c, sizeof a)
#define CLR(a) memset(a, 0, sizeof a)
#define pii pair<int, int>
#define pcc pair<char, char>
#define pic pair<int, char>
#define pci pair<char, int>
#define mii map<int, int>
#define msd map<string, double>
#define msi map<string, int>
#define ti3 tuple<int, int, int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout << #x << ": " << x << endl
#define DEBUG(x) cout << #x << ": " << x << endl
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define pi 2 * acos(0.0)
#define INFILE() freopen("in0.txt", "r", stdin)
#define OUTFILE() freopen("out0.txt", "w", stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define FST first
#define SEC second
#define SORT(v) sort(ALL(v));
#define VVI(v, n1, n2) vector<vector<int>> v(n1, vector<int>(n2, 0));
#define int(x)                                                                 \
  int x;                                                                       \
  scanf("%d", &x);
#define lint(x)                                                                \
  long long x;                                                                 \
  scanf("%lld", &x);
#define vint(v, n)                                                             \
  vector<int> v(n);                                                            \
  REP(i, n) scanf("%d", &v[i]);
#define vvint(v, n1, n2)                                                       \
  vector<vector<int>> v(n1, vector<int>(n2, 0));                               \
  REP(i, n1) REP(j, n1) scanf("%d", &v[i][j]);
#define vlint(v, n)                                                            \
  vector<ll int> v(n);                                                         \
  REP(i, n) scanf("%lld", &v[i]);
#define vvlint(v, n1, n2)                                                      \
  vector<vector<ll int>> v(n1, vector<ll int>(n2, 0));                         \
  REP(i, n1) REP(j, n1) scanf("%lld", &v[i][j]);
#define double(x)                                                              \
  double x;                                                                    \
  scanf("%lf", &x);
#define vdouble(v, n)                                                          \
  vector<double> v(n);                                                         \
  REP(i, n) scanf("%lf", &v[i]);
#define vvdoube(v, n1, n2)                                                     \
  vector<vector<double>> v(n1, vector<double>(n2, 0));                         \
  REP(i, n1) REP(j, n1) scanf("%lf", &v[i][j]);
#define char(x)                                                                \
  char x;                                                                      \
  scanf("%c", &x);
#define vchar(v, n)                                                            \
  vector<char> v(n);                                                           \
  REP(i, n) scanf("%c", &v[i]);
#define vvchar(v, n1, n2)                                                      \
  vector<vector<char>> v(n1, vector<char>(n2, 0));                             \
  REP(i, n1) REP(j, n1) scanf("%c", &v[i][j]);
#define string(x)                                                              \
  string x;                                                                    \
  cin >> x;
#define vstring(v, n)                                                          \
  vector<string> v(n);                                                         \
  REP(i, n) cin >> v(i);

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]));

ll int dp[200][200][3001] = {0};

int main() {

  int(N) int(A) vint(v, N) dp[0][0][0] = 1;
  FOR(j, 0, N) {
    FOR(k, 0, N + 1) {
      REP(l, A * N + 1) {
        dp[j + 1][k][l] += dp[j][k][l];
        dp[j + 1][k + 1][l + v[j]] += dp[j][k][l];
      }
    }
  }
  ll int ans = 0;
  FOR(k, 1, N + 1) { ans += dp[N][k][k * A]; }
  printf("%lld\n", ans);
  return 0;
}