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

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

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef vector<int> Array;
typedef vector<vector<int>> Array2;
typedef vector<LL> LArray;
typedef vector<P> PArray;
typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() {
  int itiv;
  return (cin >> itiv, itiv);
}
template <typename T> void readAll(vector<T> &vec) {
  for (int i = 0, size = vec.size(); i < size; i++)
    cin >> vec[i];
}
template <typename T, typename U> void readAll(vector<pair<T, U>> &vec) {
  for (int i = 0, size = vec.size(); i < size; i++)
    cin >> vec[i].first >> vec[i].second;
}
template <typename T> inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int dr[] = {0, -1, 0, 1}, dc[] = {-1, 0, 1, 0};

int dp[31][1 << 16];
int bitCount(int i) {
  i = i - ((i >> 1) & 0x55555555);
  i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
  i = (i + (i >> 4)) & 0x0f0f0f0f;
  i = i + (i >> 8);
  i = i + (i >> 16);
  return i & 0x3f;
}

int main(void) {
  ios::sync_with_stdio(false);
  int n, c;
  while (cin >> n >> c && n) {
    memset(dp, -1, sizeof(dp));
    Array beats(n);
    Array pushes(c);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 16; j++) {
        beats[i] = (beats[i] << 1) | getInt();
      }
    }
    for (int i = 0; i < c; i++) {
      for (int j = 0; j < 16; j++) {
        pushes[i] = (pushes[i] << 1) | getInt();
      }
    }

    dp[0][0] = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 1 << 16; j++) {
        if (dp[i][j] == -1)
          continue;

        int cb = j | beats[i];
        for (int k = 0; k < c; k++) {
          int num = bitCount(cb & pushes[k]);
          int nb = cb & ~pushes[k];
          dp[i + 1][nb] = max(dp[i + 1][nb], dp[i][j] + num);
          ans = max(dp[i + 1][nb], ans);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;
int n, c, ans, num;
vector<int> dp;
vector<vector<int>> a, b;

void solve(int count) {
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < 16; j++) {
      if (a[count][j] == 1 && b[i][j] == 1) {
        num++;
        a[count][j] = 0;
      }
    }
    dp[count] = max(num, dp[count]);
    num = 0;
  }
  count++;
  if (count == n)
    return;
  for (int i = 0; i < 16; i++) {
    a[count][i] = a[count - 1][i] | a[count][i];
  }
  solve(count);
}

int main() {
  while (cin >> n >> c) {
    a.resize(n);
    b.resize(c);
    dp.resize(n);
    for (int i = 0; i < n; i++) {
      a[i].resize(16);
    }
    for (int i = 0; i < c; i++) {
      b[i].resize(16);
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < 16; j++) {
        cin >> a[i][j];
      }
    }
    for (int i = 0; i < c; i++) {
      for (int j = 0; j < 16; j++) {
        cin >> b[i][j];
      }
    }
    solve(0);
    for (int i = 0; i < n; i++) {
      ans += dp[i];
    }
    cout << ans << endl;
    ans = 0;
    for (int i = 0; i < n; i++) {
      dp[i] = 0;
    }
    a.clear();
    b.clear();
  }
}