Problem p00343 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define fore(i, a) for (__typeof(a.begin()) i = a.begin(); i != a.end(); ++i)
#define __unique(V) V.resize(unique(V.begin(), V.end()) - V.begin())
#define cntbit(X) __builtin_popcount(X)
#define fi first
#define se second
#define LL long long
#define ii pair<int, int>
#define iii pair<int, ii>
#define TASK "sevens"
using namespace std;
int F[65][65][2], m, a[10], b[10], n;
bool ok[15];
///--------------------------
void readf() {
  memset(ok, 0, sizeof(ok));
  ok[7] = 1;
  fo(i, 1, 6) cin >> a[i], ok[a[i]] = 1;
  m = 0;
  fo(i, 1, 13) if (!ok[i]) b[++m] = i;
}
///--------------------------
inline void on(int &X, int i) { X = (X | (1 << (i - 1))); }
inline int bit(int X, int i) { return ((X >> (i - 1)) & 1); }
///--------------------------
bool dp(int mask1, int mask2, int id) {
  if (F[mask1][mask2][id] != -1)
    return F[mask1][mask2][id];
  bool rs = &F[mask1][mask2][id];
  if (mask1 == 0 && id == 0)
    return (rs = 1);
  if (mask2 == 0 && id == 1)
    return (rs = 1);
  int tmp = 0;
  on(tmp, 7);
  fo(i, 1, 6) if (!bit(mask1, i)) on(tmp, a[i]);
  fo(i, 1, 6) if (!bit(mask2, i)) on(tmp, b[i]);
  rs = 0;
  if (id == 0) {
    int yes = 0;
    fo(i, 1, 6) if (bit(mask1, i) &&
                    ((a[i] > 1 && bit(tmp, a[i] - 1)) || bit(tmp, a[i] + 1))) {
      rs |= (!dp(mask1 & (~(1 << (i - 1))), mask2, 1));
      yes = 1;
    }
    if (yes == 0)
      rs |= (!dp(mask1, mask2, 1));
    return rs;
  } else {
    int yes = 0;
    fo(i, 1, 6) if (bit(mask2, i) &&
                    ((b[i] > 1 && bit(tmp, b[i] - 1)) || bit(tmp, b[i] + 1))) {
      rs |= (!dp(mask1, mask2 & (~(1 << (i - 1))), 0));
      yes = 1;
    }
    if (yes == 0)
      rs |= (!dp(mask1, mask2, 0));
    return rs;
  }
}
///--------------------------
void solve() {
  memset(F, -1, sizeof(F));
  cout << (dp(63, 63, 0) ? "yes\n" : "no\n");
}
///--------------------------
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen(TASK ".inp", "r", stdin);
  freopen(TASK ".out", "w", stdout);
#endif // ONLINE_JUDGE
  cin >> n;
  while (n--) {
    readf();
    solve();
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define fore(i, a) for (__typeof(a.begin()) i = a.begin(); i != a.end(); ++i)
#define __unique(V) V.resize(unique(V.begin(), V.end()) - V.begin())
#define cntbit(X) __builtin_popcount(X)
#define fi first
#define se second
#define LL long long
#define ii pair<int, int>
#define iii pair<int, ii>
#define TASK "sevens"
using namespace std;
int F[65][65][2], m, a[10], b[10], n;
bool ok[15];
///--------------------------
void readf() {
  memset(ok, 0, sizeof(ok));
  ok[7] = 1;
  fo(i, 1, 6) cin >> a[i], ok[a[i]] = 1;
  m = 0;
  fo(i, 1, 13) if (!ok[i]) b[++m] = i;
}
///--------------------------
inline void on(int &X, int i) { X = (X | (1 << (i - 1))); }
inline int bit(int X, int i) { return ((X >> (i - 1)) & 1); }
///--------------------------
bool dp(int mask1, int mask2, int id) {
  if (F[mask1][mask2][id] != -1)
    return F[mask1][mask2][id];
  bool rs = &F[mask1][mask2][id];
  if (mask1 == 0 && id == 0)
    return (rs = 1);
  if (mask2 == 0 && id == 1)
    return (rs = 1);
  int tmp = 0;
  on(tmp, 7);
  fo(i, 1, 6) if (!bit(mask1, i)) on(tmp, a[i]);
  fo(i, 1, 6) if (!bit(mask2, i)) on(tmp, b[i]);
  rs = 0;
  if (id == 0) {
    int yes = 0;
    fo(i, 1, 6) if (bit(mask1, i) &&
                    ((a[i] > 1 && bit(tmp, a[i] - 1)) || bit(tmp, a[i] + 1))) {
      rs |= (!dp(mask1 & (~(1 << (i - 1))), mask2, 1));
      yes = 1;
    }
    if (yes == 0)
      rs |= (!dp(mask1, mask2, 1));
    return rs;
  } else {
    int yes = 0;
    fo(i, 1, 6) if (bit(mask2, i) &&
                    ((b[i] > 1 && bit(tmp, b[i] - 1)) || bit(tmp, b[i] + 1))) {
      rs |= (!dp(mask1, mask2 & (~(1 << (i - 1))), 0));
      yes = 1;
    }
    if (yes == 0)
      rs |= (!dp(mask1, mask2, 0));
    return rs;
  }
}
///--------------------------
void solve() {
  memset(F, -1, sizeof(F));
  cout << (dp(63, 63, 0) ? "yes\n" : "no\n");
}
///--------------------------
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  while (n--) {
    readf();
    solve();
  }
}