Problem p03665 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i, n) for (ll i(0); (i) < (n); (i)++)
#define rep(i, n) for (ll i(0); (i) < (n); (i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
const ll P60 = (1LL << 60) - 93LL;
const long long MOD = 2;

//* calculate C(n, 0), C(n, 1), ... C(n, n) list in O(n)
// ! when n < 63
vll comb_list(ll n) {
  vll res(n, 1);
  for (ll k = 1; k <= n; k++) {
    res[k] = res[k - 1] * (n - k + 1) / k;
  }
  return res;
}

void solve(long long N, long long P, std::vector<long long> A) {
  ll nrOdd = 0, nrEven = 0;
  REP(i, N) {
    if (A[i] % 2 == 0)
      nrEven++;
    else
      nrOdd++;
  }
  ll res = 1LL;
  REP(i, nrEven) res *= 2;
  ll res1 = 0;

  vll clist = comb_list(nrOdd);

  if (P) { //* sum is odd
    for (ll i = 1; i <= nrOdd; i += 2) {
      res1 += clist[i];
    }
  } else { //* sum is even
    for (ll i = 0; i <= nrOdd; i += 2) {
      res1 += clist[i];
    }
  }
  cout << res * res1 << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long P;
  scanf("%lld", &P);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, P, std::move(A));
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i, n) for (ll i(0); (i) < (n); (i)++)
#define rep(i, n) for (ll i(0); (i) < (n); (i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
const ll P60 = (1LL << 60) - 93LL;
const long long MOD = 2;

//* calculate C(n, 0), C(n, 1), ... C(n, n) list in O(n)
// ! when n < 63
vll comb_list(ll n) {
  vll res(n + 1, 1);
  for (ll k = 1; k <= n; k++) {
    res[k] = res[k - 1] * (n - k + 1) / k;
  }
  return res;
}

void solve(long long N, long long P, std::vector<long long> A) {
  ll nrOdd = 0, nrEven = 0;
  REP(i, N) {
    if (A[i] % 2 == 0)
      nrEven++;
    else
      nrOdd++;
  }
  ll res = 1LL;
  REP(i, nrEven) res *= 2;
  ll res1 = 0;

  vll clist = comb_list(nrOdd);

  if (P) { //* sum is odd
    for (ll i = 1; i <= nrOdd; i += 2) {
      res1 += clist[i];
    }
  } else { //* sum is even
    for (ll i = 0; i <= nrOdd; i += 2) {
      res1 += clist[i];
    }
  }
  cout << res * res1 << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long P;
  scanf("%lld", &P);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, P, std::move(A));
  return 0;
}