alexjercan/bugnet huggingface dataset:
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

using ull = unsigned long long;

#define Rep(i, n) for (int i = 0; i < (int)(n); ++i)

int solve() {
  int N;
  cin >> N;

  vector<ull> A(N);
  Rep(n, N) cin >> A[n];

  string S;
  cin >> S;

  vector<ull> basis;
  for (int n = N - 1; n >= 0; n--) {
    ull a = A[n];
    for (auto b : basis) {
      a = min(a, a ^ b);
    }
    if (a != 0) {
      if (S[n] == '0') {
        basis.push_back(a);
      } else if (S[n] == '1') {
        return 1;
      } else {
        abort();
      }
    }
  }

  return 0;
}

int main() {
  int T;
  cin >> T;
  Rep(t, T) { cout << solve() << endl; }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define Rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define For(i, s, n) for (int i = s; i < (int)(n); ++i)

set<int> eliminate(vector<int> a) {
  vector<int> basis;
  for (int i : a) {
    for (int b : basis) {
      int x = i ^ b;
      if (x < i)
        i = x;
    }
    if (i)
      basis.push_back(i);
  }

  // normalize
  for (;;) {
    bool changed = false;
    Rep(i, basis.size()) {
      For(j, i + 1, basis.size()) {
        int x = basis[i] ^ basis[j];
        if (x < basis[i]) {
          basis[i] = x;
          changed = true;
        }
      }
    }
    if (!changed)
      break;
  }

  return set<int>(basis.begin(), basis.end());
}

// Returns true iff all of b is contained by a
bool contains(set<int> a, set<int> b) {
  for (int i : b) {
    if (a.count(i) == 0)
      return false;
  }
  return true;
}

int main() {
  int T;
  cin >> T;
  Rep(t, T) {
    int N;
    cin >> N;
    vector<int> a(N);
    Rep(n, N) { cin >> a[n]; }

    string S;
    cin >> S;

    if (S[S.size() - 1] == '1') {
      cout << 1 << endl;
      continue;
    }

    vector<int> a0, a1;
    Rep(n, N) {
      if (S[n] == '0') {
        a0.push_back(a[n]);
      } else if (S[n] == '1') {
        a1.push_back(a[n]);
      } else {
        abort();
      }
    }

    set<int> eliminated_a0 = eliminate(a0);
    set<int> eliminated_a1 = eliminate(a1);

    if (contains(eliminated_a0, eliminated_a1)) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;

    vector<ll> b;
    bool canConsist = true;
    for (int i = n - 1; i >= 0; i--) {
      for (auto x : b) {
        a[i] = min(a[i], a[i] ^ x);
      }

      if (a[i] > 0) {
        if (s[i] == '1') {
          cout << 1 << endl;
          canConsist = false;
          break;
        }

        b.emplace_back(a[i]);
      }
    }
    if (!canConsist) {
      continue;
    }

    cout << 0 << endl;
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;

    set<ll> s0;
    s0.insert(0);
    for (int i = n - 1; i >= 0; i--) {

      if (s[i] == '0') {
        set<ll> s1(s0);

        for (auto it = s0.begin(); it != s0.end(); it++) {

          s1.insert(*it ^ a[i]);
        }
        s0 = s1;
      } else {
        if (s0.find(a[i]) == s0.end()) {
          s0.clear();
        }
      }
    }

    if (s0.find(0) != s0.end()) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
  }
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

void solve() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  string S;
  cin >> S;
  vector<ll> B;
  set<ll> se;
  se.insert(0);
  rrep(i, N) {
    ll a = A[i];
    for (ll b : B)
      a = min(a ^ b, a);
    if (S[i] == '0') {
      B.emplace_back(a);
    } else {
      if (a != 0) {
        cout << 1 << endl;
        return;
      }
    }
  }
  cout << 0 << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  rep(t, T) solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

void solve() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  string S;
  cin >> S;
  set<ll> se;
  se.insert(0);
  rrep(i, N) {
    set<ll> tmp;
    if (S[i] == '0') {
      for (auto ele : se)
        tmp.insert(ele ^ A[i]);
      for (auto ele : tmp)
        se.insert(ele);
    } else {
      if (!se.count(A[i])) {
        cout << 1 << endl;
        return;
      }
    }
  }
  cout << 0 << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  rep(t, T) solve();
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    vector<long long> b;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      long long cur = a[i];
      for (auto &x : b) {
        cur = min(cur, cur ^ x);
      }
      if (cur > 0) {
        if (s[i] == '1') {
          ans = 1;
          break;
        } else {
          b.push_back(cur);
        }
      }
    }
    cout << ans << '\\n';
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    set<long long> st;
    st.insert(0);
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '0') {
        set<long long> next = st;
        for (auto &x : st) {
          next.insert(x ^ a[i]);
        }
        swap(st, next);
      } else if (!st.count(a[i])) {
        st.clear();
      }
    }
    if (st.count(0)) {
      cout << 0 << '\\n';
    } else {
      cout << 1 << '\\n';
    }
  }
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int nth_bit(int64_t num, int n) { return (num >> n) & 1; }

int64_t msb(int64_t v) {
  v = v | (v >> 1);
  v = v | (v >> 2);
  v = v | (v >> 4);
  v = v | (v >> 8);
  v = v | (v >> 16);
  v = v | (v >> 32);
  return v ^ (v >> 1);
}

struct GJ_Xor {
  vector<int64_t> V;

  void add(int64_t a) {
    for (int64_t v : V)
      if (msb(v) & a)
        a ^= v;
    if (a > 0) {
      for (int64_t &v : V)
        if (msb(a) & v)
          v ^= a;
      V.push_back(a);
      sort(V.rbegin(), V.rend());
    }
  }

  bool belong(int64_t a) {
    for (int64_t v : V)
      if (msb(v) & a)
        a ^= v;
    return a == 0;
  }
};

bool solve() {
  int N;
  cin >> N;
  vector<int64_t> A(N), S(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  string str;
  cin >> str;
  for (int i = 0; i < N; i++)
    S[i] = (str[i] == '1');

  reverse(A.begin(), A.end());
  reverse(S.begin(), S.end());
  GJ_Xor gj;
  for (int i = 0; i < N; i++) {
    if (S[i] == 0) {
      gj.add(A[i]);
    } else {
      if (!gj.belong(A[i]))
        return 1;
    }
  }
  return 0;
}

int main() {
  int T;
  cin >> T;
  while (T--)
    cout << (solve() ? 1 : 0) << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

bool solve() {
  int N;
  cin >> N;
  vector<int64_t> A(N), S(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  string str;
  cin >> str;
  for (int i = 0; i < N; i++)
    S[i] = (str[i] == '1');

  reverse(A.begin(), A.end());
  reverse(S.begin(), S.end());
  set<int64_t> st = {0};
  for (int i = 0; i < N; i++) {
    if (S[i] == 0) {
      vector<int64_t> add;
      for (auto v : st)
        add.push_back(v ^ A[i]);
      for (auto v : add)
        st.insert(v);
    } else {
      vector<int64_t> del;
      for (auto v : st)
        if (!st.count(v ^ A[i]))
          del.push_back(v);
      for (auto v : del)
        st.erase(v);
    }
  }
  return (st.count(0) == 0);
}

int main() {
  int T;
  cin >> T;
  while (T--)
    cout << (solve() ? 1 : 0) << endl;
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\\n'
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 998244353;
signed main() {
  ll t;
  cin >> t;
  while (t) {
    t--;
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    string s;
    cin >> s;
    bool f = 1;
    set<ll, greater<ll>> st;
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '0') {
        for (auto e : st) {
          a[i] = min(a[i], a[i] ^ e);
        }
        if (a[i])
          st.insert(a[i]);
      } else {
        for (auto e : st) {
          a[i] = min(a[i], a[i] ^ e);
        }
        if (a[i])
          f = 0;
      }
    }
    if (f)
      cout << 0 << endl;
    else
      cout << 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\\n'
#define fi first
#define se second
typedef unsigned long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 998244353;
signed main() {
  ll t;
  cin >> t;
  while (t) {
    t--;
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    string s;
    cin >> s;
    bool f = 1;
    vector<ll> mat(0);
    ll rank = 0;
    for (int i = n - 1; i >= 0; i--) {
      sort(rall(mat));
      vector<ll> ma(rank);
      rep(j, rank) {
        for (int k = 64; k >= 0; k--) {
          if ((1LL << k) & mat[j]) {
            ma[j] = k;
            break;
          }
        }
      }
      rep(j, rank) {
        rep(k, j) {
          if ((1LL << ma[j]) & mat[k])
            mat[k] ^= mat[j];
        }
      }
      if (s[i] == '0') {
        rep(j, rank) {
          for (int k = 64; k >= 0; k--) {
            if ((1LL << k) & a[i]) {
              if (mat[j] & (1LL << k))
                a[i] ^= mat[j];
              break;
            }
          }
        }
        if (a[i] == 0)
          continue;
        else {
          mat.pb(a[i]);
          rank++;
        }
      } else {
        rep(j, rank) {
          for (int k = 64; k >= 0; k--) {
            if ((1LL << k) & a[i]) {
              if (mat[j] & (1LL << k))
                a[i] ^= mat[j];
              break;
            }
          }
        }
        if (a[i] == 0)
          continue;
        else
          f = 0;
      }
    }
    rep(i, rank) {}
    cout << (f ? 0 : 1) << endl;
  }
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*
最後の0ラッシュで作れる値と同じだったらOKとか
10^18までふえうるかな
setとsort+uniqueどっちが時間かかるか
mapなら早いとかある？

くそう
mapでも超でかいメモリ。入る数字が多いということか
調整できないやつを探すとか
00001
00010
00100
01000
10000
の5個があれば、どれでも調整可能
調整できない桁を探すとか
010
111
101

010

101はいけるとか
最大2^100 2^100になるか
桁でみる？
さっぱりわからん
set,map,sort+unique全部だめ。
map有力だと思ったんだが
せいぜい2^30くらいまで

むしできるbit桁を探す
それででたのがM4かな
もっと短縮せな

項目3つって、パターン少ないの

うしろから見る。0になる要素なら継続、そうじゃないなら1で終了
*/
int main() {
  ll T, N;
  cin >> T;
  for (ll i = 0; i < T; i++) {
    cin >> N;
    vector<ll> A(N, 0);
    for (ll j = 0; j < N; j++)
      cin >> A[j];
    string S;
    cin >> S;
    vector<ll> DP(1, 0); // ありえる要素の最小値を追加
    bool end = false;
    for (ll j = N - 1; j >= 0; j--) {
      ll tmp = A[j];
      for (auto v : DP)
        tmp = min(tmp, tmp ^ v);
      if (S[j] == '0' && tmp > 0)
        DP.emplace_back(tmp);
      else {
        if (tmp > 0) { // 存在しなかったら0にならない
          end = true;
          break;
        }
      }
    }
    cout << end << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*
最後の0ラッシュで作れる値と同じだったらOKとか
10^18までふえうるかな
setとsort+uniqueどっちが時間かかるか
mapなら早いとかある？

くそう
mapでも超でかいメモリ。入る数字が多いということか
調整できないやつを探すとか
00001
00010
00100
01000
10000
の5個があれば、どれでも調整可能
調整できない桁を探すとか
010
111
101

010

101はいけるとか
最大2^100 2^100になるか
桁でみる？
さっぱりわからん
set,map,sort+unique全部だめ。
map有力だと思ったんだが
せいぜい2^30くらいまで

むしできるbit桁を探す
それででたのがM4かな
もっと短縮せな

項目3つって、パターン少ないの

うしろから見る。0になる要素なら継続、そうじゃないなら1で終了
*/
int main() {
  ll T, N;
  cin >> T;
  for (ll i = 0; i < T; i++) {
    vector<ll> A(0, 0);
    cin >> N;
    for (ll j = 0; j < N; j++) {
      ll a;
      cin >> a;
      A.emplace_back(a);
    }
    string S;
    cin >> S;
    ll ssz = S.size();
    // 最後の0が続いてる箇所で、それまでのありうる数字全部を全探
    vector<ll> M1, M2; // ありえる数字を全部格納
    M2.emplace_back(0);
    bool end = false;
    for (ll j = ssz - 1; j >= 0; j--) {
      if (S[j] == '0') {
        M1 = M2;
        for (auto v : M1) {
          ll tmp = v;
          tmp = tmp ^ A[j];
          M2.emplace_back(min(A[j], tmp));
        }
        sort(M2.begin(), M2.end());
        M2.erase(unique(M2.begin(), M2.end()), M2.end());
      } else {
        auto IT = lower_bound(M2.begin(), M2.end(), A[j]);
        if (*IT != A[j]) {
          cout << 1 << endl;
          end = true;
          break;
        }
        // 含まれていたら
        M2.erase(IT);
      }
    }
    if (!end)
      cout << 0 << endl;
  }
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

void Solve() {
  int n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  string s;
  cin >> s;

  vll bases;

  rep3rev(i, n - 1, 0) {
    for (auto base : bases) {
      chmin(a[i], a[i] ^ base);
    }
    if (a[i]) {
      if (s[i] == '0') {
        bases.pb(a[i]);
      } else {
        cout << 1 << endl;
        return;
      }
    }
  }
  cout << 0 << endl;
  return;
}

void Main() {
  // AGC045 - A - Xor Battle //
  int t;
  cin >> t;
  while (t--) {
    Solve();
  }
  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Solve() {
  int n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  string s;
  cin >> s;

  vector<set<ll>> dp(n + 1);
  dp[n].insert(0);

  rep3rev(i, n - 1, 0) {
    if (s[i] == '0') {
      dp[i] = dp[i + 1];
      for (auto v : dp[i + 1])
        dp[i].insert(v ^ a[i]);
    }
    if (s[i] == '1') {
      auto itr = dp[i + 1].find(a[i]);

      if (itr != dp[i + 1].end()) {
        dp[i] = dp[i + 1];
      } else {
        dp[i].clear();
      }
    }
  }
  auto itr = dp[0].find(a[0]);

  if (itr != dp[0].end())
    cout << 0 << endl;
  else
    cout << 1 << endl;
  return;
}

void Main() {
  // AGC045 - A - Xor Battle //
  int t;
  cin >> t;
  while (t--) {
    Solve();
  }
  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <set>
#include <vector>
using namespace std;

template <typename T> void chmin(T &a, T b) { a = min(a, b); }

void solve() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  string S;
  cin >> S;
  // S の最後が '1' で，A.back() != 0 -> 1
  // A.back() == 0 だったら勝敗はそこで変わらないので，N = N-1
  // としても変わらない S.back() == '0' and A.back() != 0 -> ?

  vector<long long> base;
  for (int i = N - 1; i >= 0; --i) {
    long long e = A[i];
    if (S[i] == '0') {
      for (auto b : base)
        chmin(e, e ^ b);
      if (e)
        base.push_back(e);
    } else {
      vector<long long> base_;
      for (auto b : base) {
        if ((e ^ b) < e) {
          e ^= b;
        } else {
          base_.push_back(b);
        }
      }
      if (e != 0) {
        puts("1");
        return;
      }
      base_.push_back(A[i]);
    }
    // cerr << "base : ";
    // for(auto e : base){
    //   cerr << e << " ";
    // }
    // cerr << endl;
    if (base.empty()) {
      puts("1");
      return;
    }
  }
  if (base.size())
    puts("0");
  else
    puts("1");
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <vector>
using namespace std;

void solve() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  string S;
  cin >> S;
  // S の最後が '1' で，A.back() != 0 -> 1
  // A.back() == 0 だったら勝敗はそこで変わらないので，N = N-1
  // としても変わらない S.back() == '0' and A.back() != 0 -> ?
  set<long long> X;
  X.emplace(0);
  for (int i = N - 1; i >= 0; --i) {
    set<long long> X_;
    if (S[i] == '0') {
      for (auto e : X) {
        X_.emplace(e ^ A[i]);
        X_.emplace(e);
      }
    } else {
      for (auto e : X) {
        if (X.count(e ^ A[i]))
          X_.emplace(e ^ A[i]);
      }
    }
    swap(X, X_);
    // cerr << "! : ";
    // for(auto e : X){
    //   cerr << e << " ";
    // }
    // cerr << endl;
  }
  if (X.size())
    puts("0");
  else
    puts("1");
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

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

long long basis[64][2];
long long A[205];
char S[205];
int basisSize[2] = {0, 0};

bool insertVector(long long mask, int mode, bool testing = false) {
  for (int i = 61; i >= 0; i--) {
    if ((mask & (1LL << i)) == 0) {
      continue;
    }
    if (!basis[i][mode]) {
      if (testing) {
        return true;
      }
      basis[i][mode] = mask;
      basisSize[mode]++;
      return true;
    }
    mask ^= basis[i][mode];
  }
  return false;
}

int main() {
  int t;
  scanf("%d", &t);

  while (t--) {
    int n;
    scanf("%d", &n);

    memset(A, 0, sizeof(A));
    memset(basis, 0, sizeof(basis));
    memset(basisSize, 0, sizeof(basisSize));

    for (int i = 0; i < n; i++) {
      scanf("%lld", &A[i]);
    }

    scanf(" %s", S);

    int winner = 0;
    for (int i = n - 1; i >= 0; i--) {
      bool temp = insertVector(A[i], 0, false);
      if (temp == true && S[i] == '1') {
        winner = 1;
        break;
      }
    }

    printf("%d\\n", winner);
  }
  return 0;
}


Error: WA

Fixed submission:

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

long long A[205];
char S[205];

int B[205][64];

int memo[205][4];

bool forbidden[205][2];
int lastBit[65];

int N;
int dp(int i, int j, int k) {
  if (i == N) {
    return j != 0;
  } else if (memo[i][j] != -1) {
    return memo[i][j];
  } else {
    int move1 = dp(i + 1, j, k);
    int move2 = dp(i + 1, j ^ A[i], k);
    int ans;
    if (S[i] == '0') {
      if (move1 == 0 || move2 == 0) {
        ans = 0;
      } else {
        ans = 1;
      }
    }
    if (S[i] == '1') {
      if (move1 == 1 || move2 == 1) {
        ans = 1;
      } else {
        ans = 0;
      }
    }
    return memo[i][j] = ans;
  }
}

int main() {
  int T;
  scanf("%d", &T);

  while (T--) {
    scanf("%d", &N);

    for (int i = 0; i < N; i++) {
      scanf("%lld", &A[i]);
    }

    memset(lastBit, 0, sizeof(lastBit));
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 61; j++) {
        B[i][j] = (A[i] & (1LL << j)) >> j;
        /*if(j < 4){
            printf("B[%d][%d]=%d\\n", i, j, B[i][j]);
        }*/
      }
    }

    scanf(" %s", S);

    memset(memo, -1, sizeof(memo));
    printf("%d\\n", dp(0, 0, 0));

    /*int ans = 0;
    memset(forbidden, 0, sizeof(forbidden));
    for(int k = 0; k < 61; k ++){
        memset(memo, -1, sizeof(memo));
        if(dp(0, 0, k) == 1){
            ans = 1;
            break;
        }
        for(int i = 0; i <= N; i ++){
            for(int j = 0; j < 2; j ++){
                if(dp(i, j, k) == 1){
                    forbidden[i][j] = true;
                    if(k<4){
                        printf("forbidden(%d, %d, %d)\\n", i, j, k);
                    }
                }
            }
        }
    }

    printf("%d\\n", ans);*/
    /*if(S[N-1] == '1'){
        printf("1\\n");
        continue;
    }*/
  }

  return 0;
}