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

#include <bits/stdc++.h>
using namespace std;
template <typename T> inline T read() {
  T x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c))
    f = c == '-', c = getchar();
  while (isdigit(c))
    x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
#define int long long
namespace run {
const int N = 209;
namespace linebasis {
int a[69];
inline void insert(int x) {
  for (int i = 63; ~i; i--)
    if ((x >> i) & 1) {
      if (!a[i])
        return a[i] = x, void();
      else
        x ^= a[i];
    }
}
inline bool check(int x) {
  for (int i = 63; ~i; i--)
    if ((x >> i) & 1)
      x ^= a[i];
  return !x;
}
} // namespace linebasis
using namespace linebasis;

int n, A[N];
char s[N];
int main() {
  int T = read<int>();
  while (T--) {
    n = read<int>();
    for (int i = 1; i <= n; i++)
      A[i] = read<int>();
    cin >> s + 1;

    memset(a, 0, sizeof a);
    int peg = 0;
    for (int i = n; i >= 1; i--)
      if (s[i] == '1' && !check(A[i]))
        peg = 1;
      else
        insert(A[i]);

    if (!peg)
      puts("0");
    else
      puts("1");
  }
  return 0;
}
} // namespace run
#undef int
int main() {
#ifdef my
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif
  return run::main();
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
template <typename T> inline T read() {
  T x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c))
    f = c == '-', c = getchar();
  while (isdigit(c))
    x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
#define int long long
namespace run {
const int N = 109;
namespace linebasis {
int a[69];
inline void insert(int x) {
  for (int i = 63; ~i; i--)
    if ((x >> i) & 1) {
      if (!a[i])
        return a[i] = x, void();
      else
        x ^= a[i];
    }
}
inline bool check(int x) {
  for (int i = 63; ~i; i--)
    if ((x >> i) & 1)
      x ^= a[i];
  return !x;
}
} // namespace linebasis
using namespace linebasis;

int n, A[N];
char s[N];
int main() {
  int T = read<int>();
  while (T--) {
    n = read<int>();
    for (int i = 1; i <= n; i++)
      A[i] = read<int>();
    cin >> s + 1;

    memset(a, 0, sizeof a);
    int peg = 0;
    for (int i = n; i >= 1; i--)
      if (s[i] == '1' && !check(A[i]))
        peg = 1;
      else
        insert(A[i]);

    if (!peg)
      puts("0");
    else
      puts("1");
  }
  return 0;
}
} // namespace run
#undef int
int main() {
#ifdef my
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif
  return run::main();
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
const int maxn = 500;
typedef pair<ll, ll> par;
const ll mod = 1e9 + 7;

int id[maxn];
ll a[maxn];
char s[maxn];

void add(int p) {

  for (int i = 63; i >= 0; i--) {
    if ((a[p] >> i) & 1) {
      if (id[i] == -1) {
        id[i] = p;
        break;
      } else {
        a[p] ^= a[id[i]];
      }
    }
  }
}

bool can(int p) {
  for (int i = 63; i >= 0; i--) {
    if ((a[p] >> i) & 1) {
      if (id[i] == -1)
        return 0;
      a[p] ^= a[id[i]];
    }
  }

  return 1;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
#ifdef acm
  freopen("a.in", "r", stdin);
#endif // acm

  int test;
  cin >> test;

  int n;
  while (test--) {
    cin >> n;
    for (int i = 1; i <= n; i++)
      cin >> a[i];

    cin >> (s + 1);

    if (s[n] == '1') {
      cout << "1\\n";
      continue;
    }

    for (int i = 0; i <= 63; i++)
      id[i] = -1;

    int winer = 0;
    for (int i = n; i >= 1; i--) {
      if (s[i] == '0')
        add(i);
      else if (!can(i)) {
        winer = 1;
        break;
      }
    }

    cout << winer << "\\n";
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
typedef long long ll;
const int maxn = 300;
typedef pair<ll, ll> par;
const ll mod = 1e9 + 7;

int id[100];
ll a[maxn];
char s[maxn];

void add(int p) {

  for (int i = 63; i >= 0; i--) {
    if ((a[p] >> i) & 1) {
      if (id[i] == -1) {
        id[i] = p;
        break;
      } else {
        a[p] ^= a[id[i]];
      }
    }
  }
}

bool can(int p) {
  for (int i = 63; i >= 0; i--) {
    if ((a[p] >> i) & 1) {
      if (id[i] == -1)
        return 0;
      a[p] ^= a[id[p]];
    }
  }

  return 1;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
#ifdef acm
  freopen("a.in", "r", stdin);
#endif // acm

  int test;
  cin >> test;

  int n;
  while (test--) {
    cin >> n;
    for (int i = 1; i <= n; i++)
      cin >> a[i];

    cin >> (s + 1);

    if (s[n] == '1') {
      cout << "1\\n";
      continue;
    }

    for (int i = 0; i <= 63; i++)
      id[i] = -1;

    for (int i = 1; i <= n; i++) {
      if (s[i] == '0')
        add(i);
    }

    int winer = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] == '0')
        continue;
      if (!can(i)) {
        winer = 1;
        break;
      }
    }

    cout << winer << "\\n";
  }

  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pi;
typedef pair<lld, lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a, b) make_pair(a, b)
bool isrange(int y, int x, int n, int m) {
  if (0 <= y && y < n && 0 <= x && x < m)
    return true;
  return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
    ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
lld arr[222];
lld base[61];
int main(void) {
  int t;
  scanf("%d", &t);
  while (t--) {
    memset(base, 0, sizeof(base));
    int n;
    scanf("%d", &n);
    for (int e = 0; e < n; e++)
      scanf("%lld", &arr[e]);
    string s;
    cin >> s;
    int err = 0;
    for (int e = n - 1; e >= 0; e--) {
      if (s[e] == '1') {
        for (int p = 60; p >= 0; p--) {
          if (arr[e] & (1ll << p)) {
            arr[e] ^= base[p];
          }
        }
        if (arr[e])
          err = 1;
      } else {
        for (int p = 60; p >= 0; p--) {
          if (arr[e] & (1ll << p)) {
            if (base[p] == 0)
              base[p] = arr[e];
            arr[e] ^= base[p];
          }
        }
      }
    }
    printf("%d\\n", err);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pi;
typedef pair<lld, lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a, b) make_pair(a, b)
bool isrange(int y, int x, int n, int m) {
  if (0 <= y && y < n && 0 <= x && x < m)
    return true;
  return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
    ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
lld arr[222];
int main(void) {
  int t;
  scanf("%d", &t);
  while (t--) {
    vector<lld> v;
    v.push_back(0);
    int n;
    scanf("%d", &n);
    for (int e = 0; e < n; e++)
      scanf("%lld", &arr[e]);
    string s;
    cin >> s;
    int err = 0;
    for (int e = n - 1; e >= 0; e--) {
      if (s[e] == '1') {
        lld vv = arr[e];
        for (int q = 0; q < 70; q++) {
          for (int p = 0; p < sz(v); p++) {
            if ((vv ^ v[p]) < vv)
              vv ^= v[p];
          }
        }
        if (vv) {
          err = 1;
          break;
        }
      } else {
        int tt = sz(v);
        for (int p = 0; p < tt; p++)
          v.push_back(v[p] ^ arr[e]);
      }
    }
    printf("%d\\n", err);
  }
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long int
#define pb push_back
#define ar array
#define mp make_pair
#define f(i, n) for (ll i = 0; i < n; i++)
#define inf INT_MAX
#define pll pair<ll, pair<ll, ll>>
const ll INF = 1e18;
void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void solve() {

  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }

  string s;
  cin >> s;
  vector<ll> basis;
  int res = 0;

  for (ll i = n - 1; i >= 0; i--) {

    for (auto b : basis) {
      a[i] = min(a[i], a[i] ^ b);
    }
    if (a[i]) {
      if (s[i] == '0') {
        basis.push_back(a[i]);
      } else {
        res = 1;
      }
    }
  }
  cout << res << endl;
}
int main() {
  init();
  ll t = 1;
  cin >> t;
  for (ll i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long int
#define pb push_back
#define ar array
#define mp make_pair
#define f(i, n) for (ll i = 0; i < n; i++)
#define inf INT_MAX
#define pll pair<ll, pair<ll, ll>>
const ll INF = 1e18;
void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

void solve() {

  ll n;
  cin >> n;
  vector<ll> A(n);
  for (ll i = 0; i < n; i++) {
    cin >> A[i];
  }
  string s;
  cin >> s;
  int S = s.length();
  set<ll> p0, p1;
  p0.insert(0);
  p1.insert(0);
  // cout<<p1.size()<<" "<<p0.size()<<"  "<<S<<" "<<endl;
  ll x;
  for (ll i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      for (auto it = p0.begin(); it != p0.end(); it++) {
        ll xorsss = *it ^ A[i];
        p0.insert(xorsss);
        // cout<<"p0 :  " <<*it<<" "<<A[i]<<" "<<xorsss<<endl;
      }
    } else {
      for (auto it = p1.begin(); it != p1.end(); it++) {
        ll xorsss = *it ^ A[i];
        p1.insert(xorsss);
        // cout<<"p1 :  "<<*it<<" "<<A[i]<<" "<<xorsss<<endl;
      }
    }
  }
  for (auto it = p1.begin(); it != p1.end(); it++) {
    if (p0.find(*it) == p0.end()) {
      cout << "1" << endl;
      return;
    }
  }
  cout << "0" << endl;
}
int main() {
  init();
  ll t = 1;
  cin >> t;
  for (ll i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll = long long;
#define int ll

const int N = 62;
const int L = 220;

int xb[N];
int len = 0;

bool bit(int m, int i) { return (m >> i) & 1LL; }

void clear() {
  fill_n(xb, N, 0);
  len = 0;
}

int check(int num) {
  for (int i = 0; i < N; ++i) {
    if (bit(num, i)) {
      num ^= xb[i];
    }
  }
  return num;
}

void add(int num) {
  num = check(num);
  if (!num) {
    return;
  }
  int ind = __builtin_ctzll(num);
  assert(0 <= ind && ind < N && bit(num, ind) && !xb[ind]);
  xb[ind] = num;
  for (int i = 0; i < N; ++i) {
    if (i != ind && bit(xb[i], ind)) {
      xb[i] ^= xb[ind];
    }
  }
}

int n;
int a[L];
string s;

void solve() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> s;
  clear();
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == '0') {
      add(a[i]);
    } else if (check(a[i])) {
      cout << "1\\n";
      return;
    }
  }
  cout << "0\\n";
}

signed main() {
#ifdef LC
  assert(freopen("input.txt", "r", stdin));
#endif
  ios::sync_with_stdio(0), cin.tie(0);
  int tn;
  cin >> tn;
  while (tn--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll = long long;
#define int ll

const int N = 62;

int xb[N];
int len = 0;

bool bit(int m, int i) { return (m >> i) & 1LL; }

void clear() {
  fill_n(xb, N, 0);
  len = 0;
}

int check(int num) {
  for (int i = 0; i < N; ++i) {
    if (bit(num, i)) {
      num ^= xb[i];
    }
  }
  return num;
}

void add(int num) {
  num = check(num);
  if (!num) {
    return;
  }
  int ind = __builtin_ctzll(num);
  assert(0 <= ind && ind < N && bit(num, ind) && !xb[ind]);
  xb[ind] = num;
  for (int i = 0; i < N; ++i) {
    if (i != ind && bit(xb[i], ind)) {
      xb[i] ^= xb[ind];
    }
  }
}

int n;
int a[N];
string s;

void solve() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> s;
  clear();
  for (int i = n - 1; i >= 0; --i) {
    if (s[i] == '0') {
      add(a[i]);
    } else if (check(a[i])) {
      cout << "1\\n";
      return;
    }
  }
  cout << "0\\n";
}

signed main() {
#ifdef LC
  assert(freopen("input.txt", "r", stdin));
#endif
  ios::sync_with_stdio(0), cin.tie(0);
  int tn;
  cin >> tn;
  while (tn--) {
    solve();
  }
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template <typename T> istream &operator>>(istream &is, vector<T> &vs) {
  for (T &v : vs)
    is >> v;
  return is;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) {
  for (const T &v : vs)
    os << v << " ";
  return os;
}

int solve() {
  int N;
  cin >> N;
  vector<LL> A(N);
  cin >> A;
  string S;
  cin >> S;

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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cout << solve() << endl;
    ;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template <typename T> istream &operator>>(istream &is, vector<T> &vs) {
  for (T &v : vs)
    is >> v;
  return is;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vs) {
  for (const T &v : vs)
    os << v << " ";
  return os;
}

int solve() {
  int N;
  cin >> N;
  vector<LL> A(N);
  cin >> A;
  string S;
  cin >> S;

  set<LL> X, Y; // X: 0, Y: 1
  int mask = ~0LL;
  for (int i = N - 1; i >= 0; --i) {
    if (S[i] == '0') {
      LL a = A[i] & mask;
      if (X.count(A[i]))
        continue;

      for (LL x : X) {
        LL v = (x ^ A[i]) & mask;
        if (__builtin_popcount(v) == 1) {
          bitset<128> b(v);
          int i = 0;
          for (; i < 128; ++i) {
            if (b.test(i))
              break;
          }
          mask = mask ^ (1 << i);
        }
        X.insert(v);
      }
      X.insert(a);
    } else {
      LL a = A[i] & mask;
      if (!X.count(a))
        return 1;
    }
  }
  return 0;
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cout << solve() << endl;
    ;
  }
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

// A.

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <vector>

using namespace std;

typedef long long LL;

bool possible(LL t, vector<LL> a) {
  if (a.empty())
    return t == 0;
  LL x = 0;
  int st = 0;
  int sz = (int)a.size();
  sort(a.rbegin(), a.rend());
  for (LL b = 60; b >= 0; --b) {
    LL f = 1LL << b;
    if (!(a[st] & f))
      continue;
    for (int i = 0; i < sz; ++i) {
      if (i != st && (a[i] & f) != 0)
        a[i] ^= a[st];
    }
    ++st;
    if (st >= sz)
      break;
    sort(a.rbegin(), a.rbegin() + sz - st);
  }
  for (LL b = 60; b >= 0; --b) {
    LL f = 1LL << b;
    if ((f & t) != 0 && (f & x) == 0) {
      for (int i = 0; i < sz; ++i) {
        if (a[i] & f) {
          x ^= a[i];
          break;
        }
      }
    }
  }
  return t == x;
}

int main(int argc, char *argv[]) {
  LL t, n;
  cin >> t;
  for (LL tt = 0; tt < t; ++tt) {
    cin >> n;
    vector<LL> a(n);
    for (LL i = 0; i < n; ++i) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    int ans = 0;
    vector<LL> x;
    for (LL i = n - 1; i >= 0; --i) {
      if (s[i] != '0') {
        if (!possible(a[i], x)) {
          ans = 1;
          break;
        }
      } else {
        x.emplace_back(a[i]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

// A.

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <vector>

using namespace std;

typedef long long LL;

bool possible(LL t, vector<LL> a) {
  LL x = 0;
  int st = 0;
  int sz = (int)a.size();
  sort(a.rbegin(), a.rend());
  for (LL b = 60; b >= 0; --b) {
    LL f = 1LL << b;
    if (!(a[st] & f))
      continue;
    for (int i = 0; i < sz; ++i) {
      if (i != st && (a[i] & f) != 0)
        a[i] ^= a[st];
    }
    ++st;
    if (st >= sz)
      break;
    sort(a.rbegin(), a.rbegin() + sz - st);
  }
  for (LL b = 60; b >= 0; --b) {
    LL f = 1LL << b;
    if ((f & t) != 0 && (f & x) == 0) {
      for (int i = 0; i < sz; ++i) {
        if (a[i] & f) {
          x ^= a[i];
          break;
        }
      }
    }
  }
  return t == x;
}

int main(int argc, char *argv[]) {
  LL t, n;
  cin >> t;
  for (LL tt = 0; tt < t; ++tt) {
    cin >> n;
    vector<LL> a(n);
    for (LL i = 0; i < n; ++i) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    int ans = 0;
    vector<LL> x;
    for (LL i = n - 1; i >= 0; --i) {
      if (s[i] != '0') {
        if (!possible(a[i], x)) {
          ans = 1;
          break;
        }
      } else {
        x.emplace_back(a[i]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

void solve() {
  int n;
  int i, j;
  cin >> n;
  ll a[n];
  for (i = 0; i < n; i++)
    cin >> a[i];
  string s;
  cin >> s;
  VI v(63, -1);
  for (i = n - 1; i >= 0; i--) {
    if (s[i] == '0') {
      for (j = 62; j >= 0; j--) {
        if ((a[i] >> j) & 1) {
          if (v[j] == -1) {
            v[j] = a[i];
            break;
          } else
            a[i] ^= v[j];
        }
      }
    } else {
      for (j = 62; j >= 0; j--) {
        if ((a[i] >> j) & 1) {
          if (v[j] != -1)
            a[i] ^= v[j];
        }
      }
      if (a[i] != 0) {
        cout << 1 << endl;
        return;
      }
    }
  }
  cout << 0 << endl;
}

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

void solve() {
  int n;
  int i, j;
  cin >> n;
  ll a[n];
  for (i = 0; i < n; i++)
    cin >> a[i];
  string s;
  cin >> s;
  set<ll> se;
  se.insert(0);
  for (i = n - 1; i >= 0; i--) {
    if (s[i] == '0') {
      VI v;
      for (auto it = se.begin(); it != se.end(); ++it)
        v.pb(*it);
      for (j = 0; j < v.size(); j++)
        se.insert(a[i] ^ v[j]);
    } else {
      set<ll> se2 = se;
      VI v;
      for (auto it = se.begin(); it != se.end(); ++it)
        v.pb(*it);
      for (j = 0; j < v.size(); j++) {
        if (!se2.count(v[j] ^ a[i])) {
          se.erase(v[j]);
        }
      }
    }
  }
  if (!se.count(0))
    cout << 1 << endl;
  else
    cout << 0 << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i, j;
  int t;
  cin >> t;
  while (t--)
    solve();
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

int calc(ll x) {
  int res = -1;
  for (int i = 0; i <= 60; i++) {
    if ((1LL << i) & x) {
      res = i;
    }
  }
  return res;
}

int main() {
  int n, t, flag;
  string s;
  set<ll> s1, s0;
  ll a[200];
  cin >> t;
  while (t--) {
    cin >> n;
    s0.clear();
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cin >> s;
    flag = 0;
    for (int i = n - 1; i >= 0 && flag == 0; i--) {
      s1.clear();
      if (s[i] == '0') {
        set<ll>::reverse_iterator it = s0.rbegin();
        while (it != s0.rend()) {
          if (calc(*it) == calc(a[i])) {
            a[i] ^= *it;
          }
          it++;
        }
        if (a[i]) {
          set<ll>::reverse_iterator it = s0.rbegin();
          while (it != s0.rend()) {
            if (calc(*it) == calc(a[i])) {
              a[i] ^= *it;
            }
            it++;
          }
          s0.insert(a[i]);
        }
      } else {
        set<ll>::reverse_iterator it = s0.rbegin();
        while (it != s0.rend()) {
          if (calc(*it) == calc(a[i])) {
            a[i] ^= *it;
          }
          it++;
        }
        if (a[i]) {
          flag = 1;
        }
      }
    }
    cout << flag << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

int calc(ll x) {
  int res = -1;
  for (int i = 0; i <= 60; i++) {
    if ((1LL << i) & x) {
      res = i;
    }
  }
  return res;
}

int main() {
  int n, t, flag;
  string s;
  set<ll> s1, s0;
  ll a[200];
  cin >> t;
  while (t--) {
    cin >> n;
    s0.clear();
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    cin >> s;
    flag = 0;
    for (int i = n - 1; i >= 0 && flag == 0; i--) {
      s1.clear();
      if (s[i] == '0') {
        for (int j = 0; j < s0.size() * s0.size() && a[i]; j++) {
          for (auto &&x : s0) {
            if (calc(x) == calc(a[i])) {
              a[i] ^= x;
            }
          }
        }
        if (a[i]) {
          for (int j = 0; j < s0.size(); j++) {
            for (auto &&x : s0) {
              if (calc(x) == calc(a[i])) {
                a[i] = a[i] ^ x;
              }
            }
          }
          s0.insert(a[i]);
        }
      } else {
        for (int j = 0; j <= s0.size() * s0.size() && a[i]; j++) {
          for (auto &&x : s0) {
            if (calc(x) == calc(a[i])) {
              a[i] = a[i] ^ x;
            }
          }
        }
        if (a[i]) {
          flag = 1;
        }
      }
    }
    cout << flag << endl;
  }
}