prithivMLmods/Coder-Stat huggingface dataset:
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define s(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vl> a(m);
  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int s;
      cin >> s;
      a[n].push_back(s);
    }
  }
  vl p(m);
  rep(i, m) cin >> p[i];
  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool f = true;
    rep(i, m) {
      int count = 0;
      for (auto v : a[i]) {
        if (bit & (1 << v))
          count++;
      }
      if (count % 2 != p[i])
        f = false;
    }
    if (f)
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define s(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vl> a(m);
  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int s;
      cin >> s;
      s--;
      a[i].push_back(s);
    }
  }
  vl p(m);
  rep(i, m) cin >> p[i];
  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool f = true;
    rep(i, m) {
      int count = 0;
      for (auto v : a[i]) {
        if (bit & (1 << v))
          count++;
      }
      if (count % 2 != p[i])
        f = false;
    }
    if (f)
      ans++;
  }
  cout << ans << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;

int MOD = 1000000007;

int main() {
  int N, M, k, ans = 0, c = 0;
  cin >> N >> M;
  vector<vector<int>> s(M + 10);
  for (int i = 0; i < M; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  vector<int> p(M + 10);
  for (int i = 0; i < M; ++i)
    cin >> p[i];

  for (int i = 0; i < (1 << N); i++) {
    bool ok = true;
    for (int j = 0; j < M; j++) {
      c = 0;
      for (int id : s[j]) {
        if ((i >> id) & 1) {
          c++;
        }
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>

using namespace std;

int MOD = 1000000007;

int main() {
  int N, M, k, ans = 0, c = 0;
  cin >> N >> M;
  vector<vector<int>> s(M + 10);
  for (int i = 0; i < M; i++) {
    cin >> k;
    s[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  vector<int> p(M + 10);
  for (int i = 0; i < M; ++i)
    cin >> p[i];

  for (int i = 0; i < (1 << N); i++) {
    bool ok = true;
    for (int j = 0; j < M; j++) {
      c = 0;
      for (int id : s[j]) {
        if ((i >> id) & 1) {
          c++;
        }
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03031 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> Bit(M, 0);
  vector<long long> mod(M, 0);
  for (int i = 0; i < N; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      Bit[i] ^= 1 << (s - 1);
    }
  }
  for (int i = 0; i < M; i++)
    cin >> mod[i];

  long long ans = 0;

  for (long long i = 0; i < (1 << N); i++) {
    bool flg = false;
    //    cout << bitset<3>(i) << "\n";
    for (int j = 0; j < M; j++) {
      //      cout << j << ' ' << __builtin_popcount(Bit[j]&i)%2 << ' ' <<
      //      mod[j] << "\n";
      if (__builtin_popcountll(Bit[j] & i) % 2 != mod[j]) {
        flg = true;
        break;
      }
    }
    if (!flg)
      ans++;
  }

  cout << ans << "\n";

  //  for (int i=0; i<M; i++) {
  //    cout << bitset<3>(Bit[i]) << "\n";
  //  }
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> Bit(M, 0);
  vector<long long> mod(M, 0);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      Bit[i] ^= 1 << (s - 1);
    }
  }
  for (int i = 0; i < M; i++)
    cin >> mod[i];

  long long ans = 0;

  for (long long i = 0; i < (1 << N); i++) {
    bool flg = false;
    //    cout << bitset<3>(i) << "\n";
    for (int j = 0; j < M; j++) {
      //      cout << j << ' ' << __builtin_popcount(Bit[j]&i)%2 << ' ' <<
      //      mod[j] << "\n";
      if (__builtin_popcountll(Bit[j] & i) % 2 != mod[j]) {
        flg = true;
        break;
      }
    }
    if (!flg)
      ans++;
  }

  cout << ans << "\n";

  //  for (int i=0; i<M; i++) {
  //    cout << bitset<3>(Bit[i]) << "\n";
  //  }
}
Problem p03031 (C++)

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

using namespace std;

int main() {
  unsigned int n, m;
  cin >> n >> m;

  vector<vector<int>> s(m);
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int a;
      cin >> a;
      a--;
      s[i].emplace_back(a);
    }
  }

  vector<int> p(m);
  for (int i = 0; i < m; ++i) {
    cin >> p[i];
  }

  auto ans = 0L;
  for (unsigned int bit = 0; bit < (1U << n); ++bit) {
    bool isOK = true;
    // 電球iがついているかどうか
    for (int i = 0; i < n; ++i) {
      int cnt = 0;
      for (unsigned int v : s[i]) {
        if (bit & (1U << v))
          ++cnt;
      }
      if (cnt % 2 != p[i])
        isOK = false;
    }
    if (isOK)
      ++ans;
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  unsigned int n, m;
  cin >> n >> m;

  vector<vector<int>> s(m);
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int a;
      cin >> a;
      a--;
      s[i].emplace_back(a);
    }
  }

  vector<int> p(m);
  for (int i = 0; i < m; ++i) {
    cin >> p[i];
  }

  auto ans = 0L;
  for (unsigned int bit = 0; bit < (1U << n); ++bit) {
    bool isOK = true;
    // 電球iがついているかどうか
    for (int i = 0; i < m; ++i) {
      int cnt = 0;
      for (unsigned int v : s[i]) {
        if (bit & (1U << v))
          ++cnt;
      }
      if (cnt % 2 != p[i])
        isOK = false;
    }
    if (isOK)
      ++ans;
  }

  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> S(N);
  rep(i, M) {
    int k;
    cin >> k;
    rep(i, k) {
      int s;
      cin >> s;
      S[s - 1].push_back(i);
    }
  }
  vector<int> p(M);
  rep(i, M) cin >> p[i];

  int cnt = 0;
  for (int bit = 0; bit < (1 << N); ++bit) {
    vector<int> X;
    rep(i, N) {
      if (bit & (1 << i))
        X.push_back(i);
    }
    vector<int> P(M, 0);
    for (int x : X) {
      for (int y : S[x])
        ++P[y];
    }
    rep(i, M) P[i] %= 2;

    bool judge = true;
    rep(i, M) {
      if (p[i] != P[i])
        judge = false;
    }
    if (judge)
      ++cnt;
  }

  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> S(N);
  rep(i, M) {
    int k;
    cin >> k;
    rep(j, k) {
      int s;
      cin >> s;
      S[s - 1].push_back(i);
    }
  }
  vector<int> p(M);
  rep(i, M) cin >> p[i];

  int cnt = 0;
  for (int bit = 0; bit < (1 << N); ++bit) {
    vector<int> X;
    rep(i, N) {
      if (bit & (1 << i))
        X.push_back(i);
    }
    vector<int> P(M, 0);
    for (int x : X) {
      for (int y : S[x])
        ++P[y];
    }
    rep(i, M) P[i] %= 2;

    bool judge = true;
    rep(i, M) {
      if (p[i] != P[i])
        judge = false;
    }
    if (judge)
      ++cnt;
  }

  cout << cnt << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, A = 0;
  cin >> N >> M;
  vector<int> k(M), p(M);
  vector<vector<int>> s(M, vector<int>(N));
  for (int i = 0; i < M; i++) {
    cin >> k.at(i);
    for (int j = 0; j < k.at(i); j++)
      cin >> s.at(i).at(j);
  }
  for (int i = 0; i < M; i++)
    cin >> p.at(i);
  for (int i = 0; i < (1 << 10); i++) {
    bitset<10> x(i);
    if (x.test(N))
      break;
    int T = 0;
    for (int j = 0; j < M; j++) {
      int S = 0;
      for (int a = 0; a < k.at(j); a++)
        if (x.test(s.at(j).at(a) - 1))
          S++;
      if (S % 2 == p.at(j))
        T++;
    }
    if (T == M)
      A++;
  }
  cout << A << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, A = 0;
  cin >> N >> M;
  vector<int> k(M), p(M);
  vector<vector<int>> s(M, vector<int>(N));
  for (int i = 0; i < M; i++) {
    cin >> k.at(i);
    for (int j = 0; j < k.at(i); j++)
      cin >> s.at(i).at(j);
  }
  for (int i = 0; i < M; i++)
    cin >> p.at(i);
  for (int i = 0; i < (1 << 10); i++) {
    bitset<10> x(i);
    if (N < 10 && x.test(N))
      break;
    int T = 0;
    for (int j = 0; j < M; j++) {
      int S = 0;
      for (int a = 0; a < k.at(j); a++)
        if (x.test(s.at(j).at(a) - 1))
          S++;
      if (S % 2 == p.at(j))
        T++;
    }
    if (T == M)
      A++;
  }
  cout << A << endl;
}
Problem p03031 (Python)

Buggy submission (status: Runtime Error):
import itertools


N, M = map(int, input().split())
connected_switches = [[int(x) - 1 for x in input().split()[1:]] for x in range(M)]
conditions = list(map(int, input().split()))

ok = 0
for patterns in itertools.product((0, 1), repeat=M):
    patterns = list(patterns)
    is_lighting = True
    for i, lights in enumerate(connected_switches):
        turned_sw = sum([patterns[x] for x in lights])
        if turned_sw % 2 != conditions[i]:
            is_lighting = False
            break
    if is_lighting:
        ok += 1

print(ok)


Fixed submission:
import itertools


N, M = map(int, input().split())
connected_switches = [[int(x) - 1 for x in input().split()[1:]] for x in range(M)]
conditions = list(map(int, input().split()))

ok = 0
for patterns in itertools.product((0, 1), repeat=N):
    patterns = list(patterns)
    is_lighting = True
    for i, lights in enumerate(connected_switches):
        turned_sw = sum([patterns[x] for x in lights])
        if turned_sw % 2 != conditions[i]:
            is_lighting = False
            break
    if is_lighting:
        ok += 1

print(ok)
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;

int N = 0, M = 0, k = 0;
long long ans = 0;

int main() {
  cin >> N >> M;
  // 繋がっているスイッチを格納するベクター
  vector<vector<int>> S(M, vector<int>(M));
  // 各電球に繋がっているスイッチの個数を格納しておく配列
  int K[M];
  // 2で割ったあまりの条件を格納しておく配列
  int P[M];
  // 入力をそれぞれに格納していく
  rep(m, M) {
    cin >> K[m];
    rep(i, K[m]) { cin >> S[m][i]; }
  }
  rep(m, M) { cin >> P[m]; }

  // ここからソルバー
  // bit全探索やる
  // まずは電球のONOFFを表すフラグを2^Nだけ考える
  rep(mask, 1 << N) {
    bool flag[N];
    rep(n, N) {
      if (mask & (1 << n))
        flag[n] = true;
      else
        flag[n] = false;
    }

    // 全ての電球について2で割ったあまりがPの条件に等しいかどうかを保存するcheckフラグ
    bool check = true;

    rep(m, M) {
      // ONの場所はtrueつまり1が格納されているのでインクリメントしていく
      int sum_flag = 0;
      rep(idx, K[m]) { sum_flag += flag[S[m][idx] - 1]; }
      // Pの条件にあっているかどうかを判断
      if (sum_flag % 2 != P[m])
        check = false;
    }
    // checkがいまだにtrueであれば全ての電球についてtureであったということ
    if (check)
      ans++;
  }
  // 解答出力
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;

int N = 0, M = 0, k = 0;
long long ans = 0;

int main() {
  cin >> N >> M;
  // 繋がっているスイッチを格納するベクター
  vector<vector<int>> S(M, vector<int>(N));
  // 各電球に繋がっているスイッチの個数を格納しておく配列
  int K[M];
  // 2で割ったあまりの条件を格納しておく配列
  int P[M];
  // 入力をそれぞれに格納していく
  rep(m, M) {
    cin >> K[m];
    rep(i, K[m]) { cin >> S[m][i]; }
  }
  rep(m, M) { cin >> P[m]; }

  // ここからソルバー
  // bit全探索やる
  // まずは電球のONOFFを表すフラグを2^Nだけ考える
  rep(mask, 1 << N) {
    bool flag[N];
    rep(n, N) {
      if (mask & (1 << n))
        flag[n] = true;
      else
        flag[n] = false;
    }

    // 全ての電球について2で割ったあまりがPの条件に等しいかどうかを保存するcheckフラグ
    bool check = true;

    rep(m, M) {
      // ONの場所はtrueつまり1が格納されているのでインクリメントしていく
      int sum_flag = 0;
      rep(idx, K[m]) { sum_flag += flag[S[m][idx] - 1]; }
      // Pの条件にあっているかどうかを判断
      if (sum_flag % 2 != P[m])
        check = false;
    }
    // checkがいまだにtrueであれば全ての電球についてtureであったということ
    if (check)
      ans++;
  }
  // 解答出力
  cout << ans << endl;
}
Problem p03031 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll, ll>
#define all(v) v.begin(), v.end()

const ll mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void) {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> s;
  rep(i, m) {
    ll k;
    cin >> k;
    rep(j, k) {
      ll a;
      cin >> a;
      a--;
      s[i].push_back(a);
    }
  }
  vector<ll> p(m);
  rep(i, m) cin >> p[i];

  ll ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool ok = true;
    rep(i, m) {
      ll cnt = 0;
      for (auto on : s[i]) {
        if (bit & (1 << on))
          cnt++;
      }
      if (cnt % 2 != p[i])
        ok = false;
    }
    if (ok)
      ++ans;
  }
  cout << ans << endl;

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll, ll>
#define all(v) v.begin(), v.end()

const ll mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void) {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> s(m);
  rep(i, m) {
    ll k;
    cin >> k;
    rep(j, k) {
      ll a;
      cin >> a;
      a--;
      s[i].push_back(a);
    }
  }
  vector<ll> p(m);
  rep(i, m) cin >> p[i];

  ll ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool ok = true;
    rep(i, m) {
      ll cnt = 0;
      for (auto on : s[i]) {
        if (bit & (1 << on))
          cnt++;
      }
      if (cnt % 2 != p[i])
        ok = false;
    }
    if (ok)
      ++ans;
  }
  cout << ans << endl;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(M);
  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;
    vec[i].resize(k);
    for (int j = 0; j < k; ++j) {
      cin >> vec[i][j];
      --vec[i][j];
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; ++i)
    cin >> p[i];
  int ans = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool ok = true;
    for (int j = 0; j < M; ++j) {
      int c = 0;
      for (int id = 0; id < vec[j].size(); id++) {
        if ((i >> vec[id][j]) & 1) {
          ++c;
        }
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    if (ok) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(M);
  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;
    vec[i].resize(k);
    for (int j = 0; j < k; ++j) {
      cin >> vec[i][j];
      --vec[i][j];
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; ++i)
    cin >> p[i];
  int ans = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool ok = true;
    for (int j = 0; j < M; ++j) {
      int c = 0;
      for (int id = 0; id < vec[j].size(); id++) {
        if ((i >> vec[j][id]) & 1) {
          ++c;
        }
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    if (ok) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  int cnt = 0;
  vector<int> a(N);

  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; k++) {
      int s = 0;
      cin >> s;
      s--;

      a[s] |= 1 << i;
    }
  }
  int p;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    p |= x << i;
  }

  for (int s = 0; s < (1 << N); s++) {
    int t = 0;
    for (int i = 0; i < N; i++) {
      if ((s >> i) & 1) {
        t ^= a[i];
      }
    }
    if (t == p) {
      cnt++;
    }
  }

  cout << cnt << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  int cnt = 0;
  vector<int> a(N);

  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s = 0;
      cin >> s;
      s--;

      a[s] |= 1 << i;
    }
  }
  int p;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    p |= x << i;
  }

  for (int s = 0; s < (1 << N); s++) {
    int t = 0;
    for (int i = 0; i < N; i++) {
      if ((s >> i) & 1) {
        t ^= a[i];
      }
    }
    if (t == p) {
      cnt++;
    }
  }

  cout << cnt << endl;
}
Problem p03031 (C++)

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

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> S[N], T(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      S[i].push_back(s - 1);
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  int sum = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    int ans = 0;
    for (int j = 0; j < M; j++) {
      int cnt = 0;
      for (int i = 0; i < S[j].size(); i++) {
        if (bit & (1 << S[j][i]))
          cnt++;
      }
      if (cnt % 2 == T[j])
        ans++;
    }
    if (ans == M)
      sum++;
  }
  cout << sum << endl;
}


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

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> S[M], T(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      S[i].push_back(s - 1);
    }
  }
  for (int i = 0; i < M; i++) {
    cin >> T[i];
  }
  int sum = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    int ans = 0;
    for (int j = 0; j < M; j++) {
      int cnt = 0;
      for (int i = 0; i < S[j].size(); i++) {
        if (bit & (1 << S[j][i]))
          cnt++;
      }
      if (cnt % 2 == T[j])
        ans++;
    }
    if (ans == M)
      sum++;
  }
  cout << sum << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> c(m, vector<int>(n, 0));
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      c.at(i).at(s - 1) = 1;
    }
  }
  vector<int> p(n);
  for (int i = 0; i < m; i++)
    cin >> p.at(i);
  int a = 0;
  for (int i = 0; i < (1 << n); i++) {
    vector<int> b(n);
    int x = i;
    for (int d = 0; d < n; d++) {
      b.at(d) = x % 2;
      x /= 2;
    }
    bool f = 1;
    for (int j = 0; j < m; j++) {
      int s = 0;
      for (int k = 0; k < n; k++)
        s += b.at(k) * c.at(j).at(k);
      f = (s % 2 == p.at(j) ? f : 0);
    }
    a += (f ? 1 : 0);
  }
  cout << a << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> c(m, vector<int>(n, 0));
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      c.at(i).at(s - 1) = 1;
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++)
    cin >> p.at(i);
  int a = 0;
  for (int i = 0; i < (1 << n); i++) {
    vector<int> b(n);
    int x = i;
    for (int d = 0; d < n; d++) {
      b.at(d) = x % 2;
      x /= 2;
    }
    bool f = 1;
    for (int j = 0; j < m; j++) {
      int s = 0;
      for (int k = 0; k < n; k++)
        s += b.at(k) * c.at(j).at(k);
      f = (s % 2 == p.at(j) ? f : 0);
    }
    a += (f ? 1 : 0);
  }
  cout << a << endl;
}
Problem p03031 (C++)

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

int main() {
  ifstream in("data1.txt");
  cin.rdbuf(in.rdbuf());
  int N, M;
  cin >> N >> M;

  vector<vector<int>> vec(M);

  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;
    vec[i].resize(k);
    for (int j = 0; j < k; ++j) {
      cin >> vec[i][j];
      --vec[i][j];
    }
  }

  vector<int> p(M);
  for (int i = 0; i < M; ++i)
    cin >> p[i];

  int ans = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool ok = true;
    for (int j = 0; j < M; ++j) {
      int c = 0;
      for (int id : vec[j]) {
        if ((i >> id) & 1) {
          ++c;
        }
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    if (ok) {
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  // ifstream in("data1.txt");
  // cin.rdbuf(in.rdbuf());
  int N, M;
  cin >> N >> M;

  vector<vector<int>> vec(M);

  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;
    vec[i].resize(k);
    for (int j = 0; j < k; ++j) {
      cin >> vec[i][j];
      --vec[i][j];
    }
  }

  vector<int> p(M);
  for (int i = 0; i < M; ++i)
    cin >> p[i];

  int ans = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool ok = true;
    for (int j = 0; j < M; ++j) {
      int c = 0;
      for (int id : vec[j]) {
        if ((i >> id) & 1) {
          ++c;
        }
      }
      c %= 2;
      if (c != p[j]) {
        ok = false;
      }
    }
    if (ok) {
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03031 (C++)

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

int main(void) {
  int n, m;
  int *k, **s, *p;
  int pattern = 1;
  int count = 0;
  cin >> n >> m;
  k = new int[m];
  s = new int *[m];
  p = new int[m];
  for (int i = 0; i < n; i++) {
    pattern *= 2;
  }
  count = pattern;
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    s[i] = new int(k[i]);
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
      s[i][j] -= 1;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  for (int bits = 0; bits < pattern; bits++) {
    for (int i = 0; i < m; i++) {
      int l = 0;
      for (int j = 0; j < k[i]; j++) {
        l += (bits >> s[i][j]) & 1;
      }
      if (l % 2 != p[i]) {
        count--;
        break;
      }
    }
  }
  cout << count << endl;

  return 0;
}


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

int main(void) {
  int n, m;
  int *k, **s, *p;
  int pattern = 1;
  int count = 0;
  cin >> n >> m;
  k = new int[m];
  s = new int *[m];
  p = new int[m];
  for (int i = 0; i < n; i++) {
    pattern *= 2;
  }
  count = pattern;
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    s[i] = new int[k[i]];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
      s[i][j] -= 1;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  for (int bits = 0; bits < pattern; bits++) {
    for (int i = 0; i < m; i++) {
      int l = 0;
      for (int j = 0; j < k[i]; j++) {
        l += (bits >> s[i][j]) & 1;
      }
      if (l % 2 != p[i]) {
        count--;
        break;
      }
    }
  }
  cout << count << endl;

  return 0;
}
Problem p03031 (C++)

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

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> b(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int i = 0; i < k; i++) {
      int s;
      cin >> s;
      b[i].push_back(s);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++)
    cin >> p[i];

  int ans = 0;
  for (int sw = 0; sw < (int)pow(2, n); sw++) {
    bool all_on = true;

    for (int i = 0; i < m; i++) {
      int on = 0;
      for (int s : b[i]) {
        on += (sw >> (s - 1)) % 2;
      }
      all_on &= (on % 2 == p[i]);
    }

    if (all_on)
      ans += 1;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> b(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      b[i].push_back(s);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++)
    cin >> p[i];

  int ans = 0;
  for (int sw = 0; sw < (int)pow(2, n); sw++) {
    bool all_on = true;

    for (int i = 0; i < m; i++) {
      int on = 0;
      for (int s : b[i]) {
        on += (sw >> (s - 1)) % 2;
      }
      all_on &= (on % 2 == p[i]);
    }

    if (all_on)
      ans += 1;
  }

  cout << ans << endl;

  return 0;
}
Problem p03031 (C++)

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);
bitset<10> connect[10];
int flag[10];

int main() {
  int n, m, tmp;
  cin >> n >> m;
  REP(i, m) {
    int k;
    cin >> k;
    REP(j, k) {
      cin >> tmp;
      connect[i].set(tmp);
    }
  }
  int res = 0;
  REP(i, m) cin >> flag[i];
  REP(i, 1 << n) {
    bitset<10> target(i);
    bool isok = true;
    REP(j, m) if ((target & connect[j]).count() % 2 != flag[j]) {
      isok = false;
      break;
    }
    if (isok)
      res++;
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);
bitset<10> connect[10];
int flag[10];

int main() {
  int n, m, tmp;
  cin >> n >> m;
  REP(i, m) {
    int k;
    cin >> k;
    REP(j, k) {
      cin >> tmp;
      connect[i].set(tmp - 1);
    }
  }
  int res = 0;
  REP(i, m) cin >> flag[i];
  REP(i, 1 << n) {
    bitset<10> target(i);
    bool isok = true;
    REP(j, m) if ((target & connect[j]).count() % 2 != flag[j]) {
      isok = false;
      break;
    }
    if (isok)
      res++;
  }
  cout << res << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> connect(n);
  vector<int> p(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    connect[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> connect[i][j];
      connect[i][j]--;
    }
  }

  for (int i = 0; i < m; i++)
    cin >> p[i];

  int ans = 0;
  for (int i = 0; i < (1 << n); i++) // 2^n通り試す
  {
    bool ok = true; // 光る？
    for (int j = 0; j < m; j++) {
      int count = 0;
      for (int id : connect[j]) {
        if ((i >> id) & 1)
          count++; // 繋がっているものの中でonの個数
      }
      count %= 2;
      if (count != p[j])
        ok = false;
    }
    if (ok == 1)
      ans++;
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> connect(m);
  vector<int> p(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    connect[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> connect[i][j];
      connect[i][j]--;
    }
  }

  for (int i = 0; i < m; i++)
    cin >> p[i];

  int ans = 0;
  for (int i = 0; i < (1 << n); i++) // 2^n通り試す
  {
    bool ok = true; // 光る？
    for (int j = 0; j < m; j++) {
      int count = 0;
      for (int id : connect[j]) {
        if ((i >> id) & 1)
          count++; // 繋がっているものの中でonの個数
      }
      count %= 2;
      if (count != p[j])
        ok = false;
    }
    if (ok == 1)
      ans++;
  }

  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> s(m);
  vector<ll> k(m);
  vector<ll> p(m);
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      ll a;
      cin >> a;
      a--;
      s[i].push_back(a);
    }
  }
  rep(i, m) cin >> p[i];

  ll ans = 0;
  for (ll bit = 0; bit < (1 << n); bit++) {
    vector<ll> cnt(n, 0);
    for (int j = 0; j < n; j++) {
      if (bit & (1 << j)) {
        cnt[j]++;
      }
    }

    vector<ll> count(m, 0);
    for (int a = 0; a < n; a++) {
      for (int b = 0; b < k[a]; b++) {
        count[a] += cnt[s[a][b]];
      }
    }

    bool flag = true;
    for (int x = 0; x < m; x++) {
      if (count[x] % 2 == p[x]) {
        flag = true;
      } else {
        flag = false;
        break;
      }
    }
    if (flag)
      ans++;
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> s(m);
  vector<ll> k(m);
  vector<ll> p(m);
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      ll a;
      cin >> a;
      a--;
      s[i].push_back(a);
    }
  }
  rep(i, m) cin >> p[i];

  ll ans = 0;
  for (ll bit = 0; bit < (1 << n); bit++) {
    vector<ll> cnt(n, 0);
    for (int j = 0; j < n; j++) {
      if (bit & (1 << j)) {
        cnt[j]++;
      }
    }

    vector<ll> count(m, 0);
    for (int a = 0; a < m; a++) {
      for (int b = 0; b < k[a]; b++) {
        count[a] += cnt[s[a][b]];
      }
    }

    bool flag = true;
    for (int x = 0; x < m; x++) {
      if (count[x] % 2 == p[x]) {
        flag = true;
      } else {
        flag = false;
        break;
      }
    }
    if (flag)
      ans++;
  }

  cout << ans << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;
int main() {
  ll N, M;
  cin >> N >> M;

  vector<vector<ll>> switches(M);
  vector<ll> p(M);

  for (ll i = 0; i < M; i++) {
    ll k;
    cin >> k;
    for (ll i = 0; i < k; i++) {
      ll s;
      cin >> s;
      switches[i].push_back(s - 1);
    }
  }

  for (ll i = 0; i < M; i++) {
    cin >> p[i];
  }

  ll ans = 0;
  // スイッチの点灯状態を全探索
  // 0ビット目が1 -> 1個目のスイッチがON
  for (ll bit = 0; bit < (1 << N); bit++) {
    bool ok = true;
    // 全ての電球に対して、点灯するどうかチェックする
    for (ll i = 0; i < M; i++) {
      // onになっているスイッチの数
      ll ons = 0;
      for (auto s : switches[i]) {
        if (bit & (1 << s)) {
          ons++;
        }
      }
      // onになっているスイッチの数の余りを計算
      if (ons % 2 != p[i]) {
        ok = false;
        break;
      }
    }

    if (ok)
      ans++;
  }

  cout << ans << endl;
}

Fixed submission:
#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;
int main() {
  ll N, M;
  cin >> N >> M;

  vector<vector<ll>> switches(M);
  vector<ll> p(M);

  for (ll i = 0; i < M; i++) {
    ll k;
    cin >> k;
    for (ll j = 0; j < k; j++) {
      ll s;
      cin >> s;
      switches[i].push_back(s - 1);
    }
  }

  for (ll i = 0; i < M; i++) {
    cin >> p[i];
  }

  ll ans = 0;
  // スイッチの点灯状態を全探索
  // 0ビット目が1 -> 1個目のスイッチがON
  for (ll bit = 0; bit < (1 << N); bit++) {
    bool ok = true;
    // 全ての電球に対して、点灯するどうかチェックする
    for (ll i = 0; i < M; i++) {
      // onになっているスイッチの数
      ll ons = 0;
      for (auto s : switches[i]) {
        if (bit & (1 << s)) {
          ons++;
        }
      }
      // onになっているスイッチの数の余りを計算
      if (ons % 2 != p[i]) {
        ok = false;
        break;
      }
    }

    if (ok)
      ans++;
  }

  cout << ans << endl;
}
Problem p03031 (C++)

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ull << 62) - 1)
#define cINFINT ((1 << 30) - 1)

#define BITREP(BIT, NUM) REP(BIT, 1 << (NUM))
#define ISBIT(BIT, INDEX) ((BIT) & (1 << (INDEX)))

int main() {
  ull n, m;
  cin >> n >> m;
  vector<ll> k(m, 0);
  vector<vector<ll>> s(m, vector<ll>(m, 0));
  vector<ll> p(m, 0);

  REP(k_, m) {
    cin >> k[k_];
    REP(s_, k[k_]) {
      cin >> s[k_][s_];
      s[k_][s_]--;
    }
  }
  REP(p_, m) cin >> p[p_];

  ll ans = 0;
  BITREP(i, n) {
    bool ok = true;
    REP(k_, m) {
      int b = 0;
      REP(s_, k[k_]) {
        if (ISBIT(i, s[k_][s_]))
          b = b == 0 ? 1 : 0;
      }
      if (b != p[k_]) {
        ok = false;
        break;
      }
    }
    if (ok)
      ++ans;
  }

  cout << ans << endl;
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ull << 62) - 1)
#define cINFINT ((1 << 30) - 1)

#define BITREP(BIT, NUM) REP(BIT, 1 << (NUM))
#define ISBIT(BIT, INDEX) ((BIT) & (1 << (INDEX)))

int main() {
  ull n, m;
  cin >> n >> m;
  vector<ll> k(m, 0);
  vector<vector<ll>> s(m, vector<ll>(n, 0));
  vector<ll> p(m, 0);

  REP(k_, m) {
    cin >> k[k_];
    REP(s_, k[k_]) {
      cin >> s[k_][s_];
      s[k_][s_]--;
    }
  }
  REP(p_, m) cin >> p[p_];

  ll ans = 0;
  BITREP(i, n) {
    bool ok = true;
    REP(k_, m) {
      int b = 0;
      REP(s_, k[k_]) {
        if (ISBIT(i, s[k_][s_]))
          b = b == 0 ? 1 : 0;
      }
      if (b != p[k_]) {
        ok = false;
        break;
      }
    }
    if (ok)
      ++ans;
  }

  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int ans, n, m, p[10], k[10], d[10][10];

void dfs(int a[], int l) {
  if (l == n) {
    bool f = true;
    for (int i = 0; i < m; i++) {
      if (a[i] != p[i])
        f = false;
    }
    if (f)
      ans++;
    return;
  }
  int aa[10];
  for (int i = 0; i < n; i++)
    aa[i] = a[i];
  for (int i = 0; i < n; i++)
    aa[i] = (aa[i] + d[l][i]) % 2;
  dfs(aa, l + 1);
  dfs(a, l + 1);
  return;
}

int main() {
  int s[10][10];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
      s[i][j]--;
      d[s[i][j]][i] = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int a[10]{0};
  dfs(a, 0);
  cout << ans << endl;
}

Fixed submission:
#include <iostream>
using namespace std;

int ans, n, m, p[10], k[10], d[10][10];

void dfs(int a[], int l) {
  if (l == n) {
    bool f = true;
    for (int i = 0; i < m; i++) {
      if (a[i] != p[i])
        f = false;
    }
    if (f)
      ans++;
    return;
  }
  int aa[10];
  for (int i = 0; i < n; i++)
    aa[i] = a[i];
  for (int i = 0; i < n; i++)
    aa[i] = (aa[i] + d[l][i]) % 2;
  dfs(aa, l + 1);
  dfs(a, l + 1);
  return;
}

int main() {
  int s[10][10];
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
      s[i][j]--;
      d[s[i][j]][i] = 1;
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int a[10]{0};
  dfs(a, 0);
  cout << ans << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RREP(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> s(M, vector<int>(M));
  vector<int> p(M);
  REP(i, 0, M) {
    cin >> k[i];
    REP(j, 0, k[i]) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  REP(i, 0, M) cin >> p[i];

  int ans = 0;           // 組み合わせ数
  REP(mask, 0, 1 << N) { // N個のスイッチの状態
    bool flag = true;    // 全ての電球が付く
    REP(i, 0, M) {       // 電球iが点灯するか？
      // 電球iに，繋がっているスイッチのうち何個がonか
      int x = 0;
      REP(j, 0, k[i]) {
        // スイッチ s[i][j]がonか？
        if (mask & (1 << s[i][j]))
          ++x;
      }
      // 電球iが点灯する
      if (x % 2 == p[i])
        continue;
      else {
        flag = false;
        break;
      }
    }
    if (flag)
      ++ans;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RREP(i, a, b) for (int(i) = (a)-1; (i) >= (b); --(i))
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  // vector<vector<int>> s(M, vector<int>(M));
  int s[20][20];
  vector<int> p(M);
  REP(i, 0, M) {
    cin >> k[i];
    REP(j, 0, k[i]) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  REP(i, 0, M) cin >> p[i];

  int ans = 0;           // 組み合わせ数
  REP(mask, 0, 1 << N) { // N個のスイッチの状態
    bool flag = true;    // 全ての電球が付く
    REP(i, 0, M) {       // 電球iが点灯するか？
      // 電球iに，繋がっているスイッチのうち何個がonか
      int x = 0;
      REP(j, 0, k[i]) {
        // スイッチ s[i][j]がonか？
        if (mask & (1 << s[i][j]))
          ++x;
      }
      // 電球iが点灯する
      if (x % 2 == p[i])
        continue;
      else {
        flag = false;
        break;
      }
    }
    if (flag)
      ++ans;
  }
  cout << ans << endl;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> connect(m);

  rep(i, 0, m) {
    int k;
    cin >> k;
    rep(i, 0, k) {
      int s;
      cin >> s;
      s--;
      connect[i].push_back(s);
    }
  }

  vector<int> p(m);
  rep(i, 0, m) cin >> p[i];

  int ans = 0;
  rep(i, 0, 1 << n) {
    bool isok = true;
    rep(j, 0, m) {
      int c = 0;
      for (int id : connect[j]) {
        if (i >> id & 1)
          c++;
      }
      c %= 2;
      if (c != p[j])
        isok = false;
    }
    if (isok)
      ans++;
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> connect(m);

  rep(i, 0, m) {
    int k;
    cin >> k;
    rep(j, 0, k) {
      int s;
      cin >> s;
      s--;
      connect[i].push_back(s);
    }
  }

  vector<int> p(m);
  rep(i, 0, m) cin >> p[i];

  int ans = 0;
  rep(i, 0, 1 << n) {
    bool isok = true;
    rep(j, 0, m) {
      int c = 0;
      for (int id : connect[j]) {
        if (i >> id & 1)
          c++;
      }
      c %= 2;
      if (c != p[j])
        isok = false;
    }
    if (isok)
      ans++;
  }

  cout << ans << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // sort
#include <cmath>
#include <iostream>
#include <map> // pair
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

void bin_vecadd(vector<int> &input) {
  int N = input.size();
  input[0]++;
  for (int i = 0; i < N; i++) {
    if (input[i] == 2) {
      input[i] = 0;
      input[i + 1]++;
    }
  }
}

int main(int argc, char const *argv[]) {

  int N, M;
  cin >> N >> M;
  vector<vector<int>> mat;
  vector<int> switch_param(M, 0);
  int k = 0;
  for (int i = 0; i < M; i++) {
    cin >> k;
    vector<int> vec(k, 0);
    for (int j = 0; j < k; j++) {
      cin >> vec[j];
    }
    mat.push_back(vec);
  }

  for (int i = 0; i < M; i++) {
    cin >> switch_param[i];
  }

  int count = 0;

  int loop = int(pow(2, N));

  vector<int> switch_vec(N, 0);
  int ans_num = 0;
  int check_signal = 1;
  int light_sum = 0;
  for (int i = 0; i < loop; i++) // パターン
  {
    for (int j = 0; j < M; j++) // 電球
    {
      for (int k = 0; k < mat[j].size(); k++) // 電球k番目
      {
        light_sum += switch_vec[mat[j][k] - 1];
      }

      if (light_sum % 2 != switch_param[j]) {
        check_signal = 0;
      }

      // init
      light_sum = 0;
    }
    // for(int j = 0; j < switch_vec.size(); j ++)
    // {
    //   cout<<switch_vec[j];
    // }

    if (check_signal == 1) {
      ans_num++;
    } else {
      check_signal = 1;
    }

    bin_vecadd(switch_vec);
  }

  cout << ans_num;

  return 0;
}


Fixed submission:
#include <algorithm> // sort
#include <cmath>
#include <iostream>
#include <map> // pair
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

void bin_vecadd(vector<int> &input) {
  int N = input.size();
  input[0]++;
  for (int i = 0; i < N; i++) {
    if (input[i] == 2) {
      input[i] = 0;
      if (i + 1 != N)
        input[i + 1]++;
    }
  }
}

int main(int argc, char const *argv[]) {

  int N, M;
  cin >> N >> M;
  vector<vector<int>> mat;
  vector<int> switch_param(M, 0);
  int k = 0;
  for (int i = 0; i < M; i++) {
    cin >> k;
    vector<int> vec(k, 0);
    for (int j = 0; j < k; j++) {
      cin >> vec[j];
    }
    mat.push_back(vec);
  }

  for (int i = 0; i < M; i++) {
    cin >> switch_param[i];
  }

  int count = 0;

  int loop = int(pow(2, N));

  vector<int> switch_vec(N, 0);
  int ans_num = 0;
  int check_signal = 1;
  int light_sum = 0;
  for (int i = 0; i < loop; i++) // パターン
  {
    for (int j = 0; j < M; j++) // 電球
    {
      for (int k = 0; k < mat[j].size(); k++) // 電球k番目
      {
        light_sum += switch_vec[mat[j][k] - 1];
      }

      if (light_sum % 2 != switch_param[j]) {
        check_signal = 0;
      }

      // init
      light_sum = 0;
    }
    // for(int j = 0; j < switch_vec.size(); j ++)
    // {
    //   cout<<switch_vec[j];
    // }

    if (check_signal == 1) {
      ans_num++;
    } else {
      check_signal = 1;
    }

    bin_vecadd(switch_vec);
  }

  cout << ans_num;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int nijou(int a) {
  int b = 1;
  rep(i, a - 1) b *= 2;
  return b;
}

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<vector<int>> a(m, vector<int>(n));
  vector<int> p(m);
  rep(i, m) {
    cin >> a[i][0];
    rep(j, a[i][0]) cin >> a[i][j + 1];
  }

  rep(i, m) cin >> p[i];

  rep(i, 1 << n) {
    vector<int> s(m);
    rep(j, n) {
      int mask = 1 << j;
      if (i & mask) {
        rep(k, m) {
          rep(l, a[k][0]) {
            if (nijou(a[k][l + 1]) == mask) {
              s[k]++;
            }
          }
        }
      }
    }
    bool ok = true;
    rep(j, m) {
      if (s[j] % 2 != p[j])
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int nijou(int a) {
  int b = 1;
  rep(i, a - 1) b *= 2;
  return b;
}

int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<vector<int>> a(m, vector<int>(n + 1));
  vector<int> p(m);
  rep(i, m) {
    cin >> a[i][0];
    rep(j, a[i][0]) cin >> a[i][j + 1];
  }

  rep(i, m) cin >> p[i];

  rep(i, 1 << n) {
    vector<int> s(m);
    rep(j, n) {
      int mask = 1 << j;
      if (i & mask) {
        rep(k, m) {
          rep(l, a[k][0]) {
            if (nijou(a[k][l + 1]) == mask) {
              s[k]++;
            }
          }
        }
      }
    }
    bool ok = true;
    rep(j, m) {
      if (s[j] % 2 != p[j])
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

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

#define N 110
int n, m;
vector<vector<int>> vec;
int p[N], a[20];

int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    vec.clear();
    vec.resize(m + 1);
    for (int i = 1, k; i <= m; ++i) {
      scanf("%d", &k);
      for (int j = 1, x; j <= k; ++j) {
        scanf("%d", &x);
        vec[x].push_back(i);
      }
    }
    for (int i = 1; i <= m; ++i) {
      scanf("%d", p + i);
    }
    int res = 0;
    for (int i = 0; i < (1 << n); ++i) {
      memset(a, 0, sizeof a);
      for (int j = 0; j < n; ++j) {
        if ((i >> j) & 1) {
          for (auto it : vec[j + 1]) {
            a[it] ^= 1;
          }
        }
      }
      bool F = 1;
      for (int i = 1; i <= m; ++i) {
        if ((p[i] ^ a[i]) == 1) {
          F = 0;
          break;
        }
      }
      res += F;
    }
    printf("%d\n", res);
  }
  return 0;
}


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

#define N 110
int n, m;
vector<vector<int>> vec;
int p[N], a[20];

int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    vec.clear();
    vec.resize(n + 1);
    for (int i = 1, k; i <= m; ++i) {
      scanf("%d", &k);
      for (int j = 1, x; j <= k; ++j) {
        scanf("%d", &x);
        vec[x].push_back(i);
      }
    }
    for (int i = 1; i <= m; ++i) {
      scanf("%d", p + i);
    }
    int res = 0;
    for (int i = 0; i < (1 << n); ++i) {
      memset(a, 0, sizeof a);
      for (int j = 0; j < n; ++j) {
        if ((i >> j) & 1) {
          for (auto it : vec[j + 1]) {
            a[it] ^= 1;
          }
        }
      }
      bool F = 1;
      for (int i = 1; i <= m; ++i) {
        if ((p[i] ^ a[i]) == 1) {
          F = 0;
          break;
        }
      }
      res += F;
    }
    printf("%d\n", res);
  }
  return 0;
}