alexjercan/bugnet huggingface dataset:
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
const int N = 220;

long long a[N];
set<long long> dp[N];

const int LOG = 60;

long long basis[LOG];

/* https://codeforces.com/blog/entry/68953 */
bool checkXor(long long mask) {
  for (int i = 0; i < LOG; i++) {
    if ((mask & (1LL << i)) == 0)
      continue;

    if (!basis[i])
      return false;

    mask ^= basis[i];
  }

  return true;
}
void insertVector(long long mask) {
  for (int i = 0; i < LOG; i++) {
    if ((mask & (1LL << i)) == 0)
      continue;

    if (!basis[i]) {
      basis[i] = mask;

      return;
    }

    mask ^= basis[i];
  }
}

int main() {
  int t;
  cin >> t;

  for (int test = 0; test < t; ++test) {
    int n;
    cin >> n;
    for (int i = 0; i < LOG; ++i) {
      basis[i] = 0;
    }

    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      dp[i].clear();
    }
    dp[n].clear();

    string s;
    cin >> s;

    int ok = 1;

    for (int i = n - 1; i >= 0; --i) {
      if (s[i] == '0') {
        insertVector(a[i]);
      } else {
        int find = checkXor(a[i]);

        if (find == 0) {
          ok = 0;
        }
      }
    }
    if (ok) {
      printf("0\\n");
    } else {
      printf("1\\n");
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
const int N = 220;

long long a[N];
set<long long> dp[N];

int main() {
  int t;
  cin >> t;

  for (int test = 0; test < t; ++test) {
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      dp[i].clear();
    }
    dp[n].clear();

    string s;
    cin >> s;

    dp[n].insert(0);

    for (int i = n - 1; i >= 0; --i) {
      if (s[i] == '0') {
        for (long long x : dp[i + 1]) {
          dp[i].insert(x);
          dp[i].insert(x ^ a[i]);
        }
      } else {
        int find = 0;
        for (long long x : dp[i + 1]) {
          if ((x ^ a[i]) == 0) {
            find = 1;
          }
        }
        if (find == 1) {
          for (long long x : dp[i + 1]) {
            dp[i].insert(x);
          }
        }
      }
    }
    if (dp[0].find(0) != dp[0].end()) {
      printf("0\\n");
    } else {
      printf("1\\n");
    }
  }
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll, ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

int main() {
  ll T;
  cin >> T;
  rep(w, T) {
    ll N;
    cin >> N;
    vec A(N);
    rep(i, N) { cin >> A.at(i); }
    string S;
    cin >> S;
    set<ll> B;
    B.insert(0);
    rep(i, N) {
      set<ll> C;
      auto b = B.end();
      ll a = A.at(N - 1 - i);
      rep(j, (ll)B.size()) {
        b--;
        a = min(a, a ^ *b);
      }
      if (S.at(N - 1 - i) == '0') {
        if (a != 0) {
          B.insert(a);
        }
      } else {
        if (a != 0) {
          B = C;
          break;
        }
      }
    }
    if (B.size() == 0) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll, ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

int main() {
  ll T;
  cin >> T;
  rep(w, T) {
    ll N;
    cin >> N;
    vec A(N);
    rep(i, N) { cin >> A.at(i); }
    string S;
    cin >> S;
    set<ll> B;
    B.insert(0);
    rep(i, N) {
      set<ll> C;
      auto b = B.begin();
      if (S.at(N - 1 - i) == '0') {
        rep(j, (ll)B.size()) {
          C.insert(*b ^ A.at(N - 1 - i));
          C.insert(*b);
          b++;
        }
        B = C;
      } else {
        if (!B.count(A.at(N - 1 - i))) {
          B = C;
        }
      }
    }
    if (B.size() == 0) {
      cout << 1 << endl;
    } else {
      cout << 0 << endl;
    }
  }
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

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

constexpr char newl = '\\n';

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

  int t;
  cin >> t;

  for (int loop = 0; loop < t; loop++) {
    int n;
    cin >> n;

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

    string s;
    cin >> s;

    if (s.back() == 1) {
      cout << 1 << newl;
      continue;
    }

    vector<P> v;
    v.push_back(P(0, {}));
    for (int i = n - 1; i >= 0; i--) {
      if (v.back().first == (s[i] - '0')) {
        v.back().second.push_back(a[i]);
      } else {
        int nex = 1 - v.back().first;
        v.push_back(P(nex, {a[i]}));
      }
    }

    for (auto &p : v) {
      sort(p.second.begin(), p.second.end());
    }

    int sz = v.size();
    vector<ll> buf;
    bool f = true;
    for (int i = 0; i < sz; ++i) {
      if (v[i].first == 0) {
        for (ll x : v[i].second)
          buf.push_back(x);
      } else {
        auto memo = buf;
        int sz2 = memo.size();
        int rank = 0;
        for (int j = 59; j >= 0; j--) {
          int pivot = -1;
          for (int k = rank; k < sz2; k++) {
            if (memo[k] >> j & 1) {
              pivot = k;
              break;
            }
          }

          if (pivot == -1)
            continue;
          swap(memo[pivot], memo[rank]);

          for (int k = 0; k < sz2; k++) {
            if (k != rank && (memo[k] >> j & 1))
              memo[k] ^= memo[rank];
          }

          for (ll &x : v[i].second) {
            if (x >> j & 1)
              x ^= memo[rank];
          }
          ++rank;
        }

        for (ll x : v[i].second) {
          if (x != 0) {
            f = false;
            break;
          }
        }

        if (!f)
          break;
      }
    }

    cout << !f << newl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\\n';

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

  int t;
  cin >> t;

  for (int loop = 0; loop < t; loop++) {
    int n;
    cin >> n;

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

    string s;
    cin >> s;

    set<ll> cand;
    cand.insert(0);
    for (int i = n - 1; i >= 0; i--) {
      set<ll> tmp;
      if (s[i] == '0') {
        for (ll x : cand) {
          tmp.insert(x);
          tmp.insert(x ^ a[i]);
        }
      } else {
        for (ll x : cand) {
          if (cand.find(x ^ a[i]) != cand.end()) {
            tmp.insert(x);
          }
        }
      }

      cand = move(tmp);
    }

    cout << cand.empty() << newl;
  }

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

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)

ll MIN(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

int main() {
  ll T;
  cin >> T;
  vector<ll> ans(T, -1);

  rep(i, T) {
    ll N;
    cin >> N;
    vector<ll> A(N, -1);
    rep(j, N) { cin >> A[j]; }
    string S;
    cin >> S;
    vector<vector<ll>> cand(N + 1, vector<ll>());
    // cand[N].push_back(0);
    bool flag = false;
    for (ll j = N - 1; j >= 0; j--) {
      ll x = A[j];
      for (auto y : cand[j + 1]) {
        x = MIN(x, x ^ y);
      }
      cand[j] = cand[j + 1];
      if (x != 0) {
        if (S[j] == '0') {
          cand[j].push_back(x);
        } else {
          flag = true;
          break;
        }
      }
    }
    if (flag) {
      ans[i] = 1;
    } else {
      ans[i] = 0;
    }
  }
  rep(i, T) { cout << ans[i] << endl; }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)

int main() {
  ll T;
  cin >> T;
  vector<ll> ans(T, -1);
  rep(i, T) {
    ll N;
    cin >> N;
    vector<ll> A(N, -1);
    rep(j, N) { cin >> A[j]; }
    string S;
    cin >> S;
    vector<vector<ll>> cand(N + 1, vector<ll>());
    cand[N].push_back(0);
    for (ll j = N - 1; j >= 0; j--) {
      if (S[j] == '0') {
        auto itr = find(cand[j + 1].begin(), cand[j + 1].end(), A[j]);
        size_t index = distance(cand[j + 1].begin(), itr);
        cand[j] = cand[j + 1];
        if (index == cand[j + 1].size()) {
          for (auto x : cand[j + 1]) {
            cand[j].push_back(x ^ A[j]);
          }
        }
      } else {
        auto itr = find(cand[j + 1].begin(), cand[j + 1].end(), A[j]);
        size_t index = distance(cand[j + 1].begin(), itr);
        if (index == cand[j + 1].size()) {
          break;
        } else {
          cand[j] = cand[j + 1];
        }
      }
    }
    if (cand[0].size() == 0) {
      ans[i] = 1;
    } else {
      ans[i] = 0;
    }
  }
  rep(i, T) { cout << ans[i] << endl; }
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/07/20 20:52:21
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<unsigned long long> A(n);
    for (auto &a : A)
      cin >> a;
    string s;
    cin >> s;
    vector<unsigned long long> B(64, -1ull);
    auto set_base = [&B](unsigned long long x) -> bool {
      for (int i = 0; i < 64; i++) {
        if ((x & (1ull << i)) == 0)
          continue;
        if (B[i] == -1ull) {
          B[i] = x;
          return true;
        }
        x ^= B[i];
      }
      return false;
    };
    auto solve = [&]() {
      for (int i = n - 1; i >= 0; i--) {
        if (set_base(A[i]) and s[i] == '1') {
          return false;
        }
      }
      return true;
    };
    cout << (solve() ? 0 : 1) << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/07/20 20:52:21
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<unsigned long long> A(n);
    for (auto &a : A)
      cin >> a;
    string s;
    cin >> s;
    auto solve = [n, &s, &A]() {
      unordered_set<unsigned long long> cands = {0};
      for (int i = n - 1; i >= 0; i--) {
        if (s[i] == '0') {
          auto nxt = cands;
          for (auto c : cands) {
            nxt.insert(c ^ A[i]);
          }
          cands = nxt;
        } else {
          if (cands.count(A[i]) == 0)
            return false;
        }
      }
      return true;
    };
    cout << (solve() ? 0 : 1) << endl;
  }

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

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define all(a) (a).begin(), (a).end()
#define fi first
#define si second
#define sz(x) (ll) x.size()
#define endl '\\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod 1000000007
#define inf 1000000000000000000
#define puts(n) cout << n;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m, v) memset(m, v, sizeof(m))
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    vi v;
    bool flag = false;
    for (ll i = n - 1; i >= 0; i--) {
      ll val = a[i];
      for (ll j = 0; j < v.size(); j++) {
        val = min(val, val ^ v[j]);
      }
      if (val != 0) {
        if (s[i] == '1') {
          cout << 1;
          flag = true;
          break;
        }
        v.pb(val);
      }
    }
    if (!flag)
      cout << 0;
    cout << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define all(a) (a).begin(), (a).end()
#define fi first
#define si second
#define sz(x) (ll) x.size()
#define endl '\\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod 1000000007
#define inf 1000000000000000000
#define puts(n) cout << n;
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m, v) memset(m, v, sizeof(m))
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    for (ll i = 0; i < n; i++) {
      cin >> a[i];
    }
    string s;
    cin >> s;
    set<ll> dp[n + 1];
    dp[n].insert(0);
    for (ll i = n - 1; i >= 0; i--) {
      if (s[i] == '0') {
        dp[i] = dp[i + 1];
        set<ll>::iterator it;
        for (it = dp[i + 1].begin(); it != dp[i + 1].end(); it++) {
          ll val = *it ^ a[i];
          dp[i].insert(val);
        }
      } else {
        if (dp[i + 1].find(a[i]) != dp[i + 1].end())
          dp[i] = dp[i + 1];
      }
    }
    if (dp[0].find(0) == dp[0].end())
      cout << 1;
    else
      cout << 0;
    cout << "\\n";
  }

  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

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

long getBit(long n) {
  long tmp = 1;
  while (n >= tmp) {
    tmp *= 2;
  }

  tmp /= 2;
  return tmp;
}

int main() {
  int t;
  cin >> t;
  vector<int> ans(t);
  for (int tt = 0; tt < t; tt++) {
    int n;
    cin >> n;
    long a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    string s;
    cin >> s;
    bool chk = true;
    vector<long> zero;
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '0') {
        zero.push_back(a[i]);
      } else {
        long tmp = a[i];
        for (int j = 0; j < zero.size(); j++) {
          sort(zero.begin() + j, zero.end(), greater<long>());
          long bit = getBit(zero[j]);
          if (bit == 0)
            break;
          for (int k = j + 1; k < zero.size(); k++) {
            if (zero[k] >= bit)
              zero[k] = zero[k] ^ zero[j];
          }
        }
        for (int j = 0; j < zero.size(); j++) {
          if (zero[j] == 0)
            break;
          if (getBit(tmp) == getBit(zero[j])) {
            tmp = tmp ^ zero[j];
          }
          if (tmp == 0)
            break;
        }

        if (tmp != 0) {
          chk = false;
          break;
        }
      }
    }
    if (chk)
      ans[tt] = 0;
    else
      ans[tt] = 1;
  }

  for (int i = 0; i < t; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

long getBit(long n) {
  long tmp = 1;
  while (n >= tmp) {
    tmp *= 2;
  }

  tmp /= 2;
  return tmp;
}

int main() {
  int t;
  cin >> t;
  vector<int> ans(t);
  for (int tt = 0; tt < t; tt++) {
    int n;
    cin >> n;
    long a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    string s;
    cin >> s;
    if (s[n - 1] == '1') {
      ans[tt] = 1;
    } else {
      vector<long> zero;
      queue<long> one;
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
          zero.push_back(a[i]);
        } else {
          one.push(a[i]);
        }
      }

      for (int i = 0; i < zero.size(); i++) {
        sort(zero.begin(), zero.end(), greater<long>());
        long bit = getBit(zero[i]);
        if (bit == 0)
          break;
        for (int j = i + 1; j < n; j++) {
          if (zero[j] >= bit)
            zero[j] -= bit;
        }
      }
      while (!one.empty()) {
        long tmp = one.front();
        for (int i = 0; i < zero.size(); i++) {
          if (getBit(tmp) == getBit(zero[i])) {
            tmp -= getBit(tmp);
          }
          if (tmp == 0)
            break;
        }
        if (tmp == 0) {
          one.pop();
        } else {
          break;
        }
      }
      if (one.empty())
        ans[tt] = 0;
      else
        ans[tt] = 1;
    }
  }

  for (int i = 0; i < t; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <string>

using namespace std;

typedef long long ll;

void Canonize(vector<ll> &a) {
  int n = a.size();
  for (;;) {
    bool ok = true;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        if (i != j && (a[i] ^ a[j]) < a[i]) {
          a[i] ^= a[j];
          ok = false;
        }
    if (ok)
      break;
  }
  vector<ll> result;
  for (ll x : a)
    if (x > 0)
      result.push_back(x);
  a = result;
}

int main() {
  ll tn;
  cin >> tn;
  for (ll tst = 0; tst < tn; ++tst) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i)
      cin >> a[i];
    string s;
    cin >> s;
    reverse(a.begin(), a.end());
    reverse(s.begin(), s.end());
    vector<ll> v;
    int winner = 0;
    for (int t = 0; t < n; ++t) {
      if (s[t] == '0') {
        v.push_back(a[t]);
        continue;
      } else {
        Canonize(v);
        int rank = v.size();
        v.push_back(a[t]);
        Canonize(v);
        if (v.size() > rank) {
          winner = 1;
          break;
        }
      }
    }
    cout << winner << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iostream>
#include <map>
#include <random>
#include <set>
#include <string>

using namespace std;

typedef long long ll;

void Canonize(vector<ll> &a) {
  // cerr << "Canonize before: "; for (ll x : a) cerr << x << " "; cerr << endl;
  for (;;) {
    bool ok = true;
    for (ll i = 0; i < a.size(); ++i)
      for (ll j = 0; j < a.size(); ++j)
        if (i != j) {
          if ((a[i] ^ a[j]) < a[i]) {
            a[i] ^= a[j];
            ok = false;
          }
        }
    if (ok) {
      // cerr << "Canonize after: "; for (ll x : a) cerr << x << " "; cerr <<
      // endl;
      return;
    }
  }
}

int main() {
  ll tn;
  cin >> tn;
  for (ll tst = 0; tst < tn; ++tst) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i)
      cin >> a[i];
    string s;
    cin >> s;
    vector<ll> v;
    ll i = 0;
    while (i < n) {
      char curPlayer = s[i];
      vector<ll> curMoves;
      while (i < n && s[i] == curPlayer) {
        curMoves.push_back(a[i]);
        i++;
      }
      Canonize(curMoves);
      for (ll c : curMoves) {
        if (curPlayer == '1') {
          v.push_back(c);
        } else {
          for (int j = 0; j < v.size(); ++j) {
            if ((v[j] ^ c) < v[j])
              v[j] ^= c;
          }
        }
      }
    }
    sort(v.begin(), v.end());
    int result = 0;
    if (v.back() > 0)
      result = 1;
    cout << result << endl;
  }
  return 0;
}
Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int t, n, x, f;
unsigned long long a[200];
unsigned long long b[64];
unsigned long long q[200];
int y[64];
char s[201];
int main() {
  scanf("%d", &t);
  b[0] = 1;
  for (int i = 1; i < 64; i++)
    b[i] = b[i - 1] * 2;
  for (int v = 0; v < t; v++) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%llu", a + i);
    }
    scanf(" %s", s);
    for (int i = 0; i < 64; i++)
      y[i] = -1;
    f = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '1') {
        for (int j = 0; j < 64; j++) {
          if (a[i] & b[j]) {
            if (y[j] == -1) {
              f = 1;
              goto X;
            } else {
              a[i] ^= q[y[j]];
            }
          }
        }
        if (a[i]) {
          f = 1;
          goto X;
        }
      } else {
        q[x] = a[i];
        for (int j = 0; j < 64; j++) {
          if (q[x] & b[j]) {
            if (y[j] != -1) {
              q[x] ^= q[y[j]];
            }
          }
        }
        for (int j = 0; j < 64; j++) {
          if (q[x] & b[j]) {
            if (y[j] == -1) {
              y[j] = x;
              break;
            }
          }
        }
        x++;
      }
    }
    x = 0;
  X:
    x = 0;
    printf("%d\\n", f);
  }
}

Error: 0

Fixed submission:

#include <stdio.h>
int t, n, x, f;
unsigned long long a[200];
unsigned long long b[64];
unsigned long long q[200];
int y[64];
char s[201];
int main() {
  scanf("%d", &t);
  b[0] = 1;
  for (int i = 1; i < 64; i++)
    b[i] = b[i - 1] * 2;
  for (int v = 0; v < t; v++) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      scanf("%lu", a + i);
    }
    scanf(" %s", s);
    for (int i = 0; i < 64; i++)
      y[i] = -1;
    f = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '1') {
        for (int j = 0; j < 64; j++) {
          if (a[i] & b[j]) {
            if (y[j] == -1) {
              f = 1;
              goto X;
            } else {
              a[i] ^= q[y[j]];
            }
          }
        }
        if (a[i]) {
          f = 1;
          goto X;
        }
      } else {
        q[x] = a[i];
        for (int j = 0; j < 64; j++) {
          if (q[x] & b[j]) {
            if (y[j] != -1) {
              q[x] ^= q[y[j]];
            }
          }
        }
        for (int j = 0; j < 64; j++) {
          if (q[x] & b[j]) {
            if (y[j] == -1) {
              y[j] = x;
              break;
            }
          }
        }
        x++;
      }
    }
    x = 0;
  X:
    printf("%d\\n", f);
  }
}
Problem p02651 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int maxn = 201;

int t, n;
long long a[maxn];
char s[maxn];
vector<long long> cur;

signed main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
      scanf("%lld", &a[i]);
    scanf("%s", &s);
    cur = {0};
    for (int i = n - 1; i >= 0; --i) {
      for (long long x : cur)
        a[i] = min(a[i], a[i] ^ x);
      if (a[i] && s[i] == '1') {
        cur.clear();
        break;
      } else if (a[i])
        cur.push_back(a[i]);
    }
    printf("%d\\n", int(cur.empty()));
  }
}


Error: TLE

Fixed submission:

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

const int maxn = 201;

int t, n;
int a[maxn];
char s[maxn];
vector<set<int>> dp;

signed main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
      scanf("%d", &a[i]);
    scanf("%s", &s);
    dp.assign(n + 1, set<int>());
    dp[n].insert(0);
    for (int i = n - 1; i >= 0; --i) {
      if (s[i] == '1' && dp[i + 1].find(a[i]) == dp[i + 1].end())
        dp[i] = set<int>();
      else if (s[i] == '1')
        dp[i] = dp[i + 1];
      else {
        for (int x : dp[i + 1]) {
          dp[i].insert(x);
          dp[i].insert(x ^ a[i]);
        }
      }
    }
    printf("%d\\n", int(dp[0].empty()));
  }
}