Problem p02651 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h> // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Jun  7 21:10:13 JST 2020
 **/
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());

int get_msb(long long x) {
  assert(x != 0);
  return 63 - __builtin_clzll(x);
}
int get_lsb(long long x) {
  assert(x != 0);
  return __builtin_ctzll(x);
}

void GaussJordan(std::vector<Int> &A, bool is_extended = false) {
  Int rank = 0;
  // for (Int col = 0; col < 62; ++col) {
  for (Int col = 62 - 1; col >= 0; col--) {
    if (is_extended && col == 62 - 1)
      break;
    Int pivot = -1;
    for (Int row = rank; row < A.size(); ++row) {
      if (A[row] >> col & 1) {
        pivot = row;
        break;
      }
    }
    if (pivot == -1)
      continue;
    std::swap(A[pivot], A[rank]);
    for (Int row = 0; row < A.size(); ++row) {
      if (row != rank && (A[row] >> col & 1))
        A[row] ^= A[rank];
    }
    ++rank;
    dump(A);
  }
  dump(A);
  REP(i, A.size() - 1) {
    if (A[i] == 0 || A[i + 1] == 0)
      continue;
    if (!(get_msb(A[i]) > get_msb(A[i + 1]))) {
      dump(get_msb(A[i]), get_msb(A[i + 1]));
      assert(false);
    };
  }
}
void solve() {
  Int n;
  std::cin >> n;
  std::vector<Int> a(n);
  REP(i, n) std::cin >> a[i];
  // REP(i, n) a[i] = rnd() % 1000000000000000001;
  std::string s;
  // REP(i, n / 2) s.push_back('0' + rnd() % 2);
  // REP(i, n - n / 2) s.push_back('0');
  std::cin >> s;
  dump(a, s);
  std::vector<Int> acc;
  for (Int i = n - 1; i >= 0; i--) {
    if (s[i] == '0') {
      acc.push_back(a[i]);
      GaussJordan(acc);
    } else {
      while (a[i]) {
        Int ms = get_msb(a[i]);
        bool ok = false;
        for (Int x : acc) {
          if (x && get_msb(x) == ms) {
            a[i] ^= x;
            assert(a[i] == 0 || get_msb(a[i]) < ms);
            ok = true;
            break;
          }
        }
        if (!ok) {
          dump(i);
          std::cout << 1 << "\\n";
          return;
        }
      }
    }
  }
  std::cout << 0 << "\\n";
}
signed main() {
  Int T;
  std::cin >> T;
  while (T--)
    solve();
}


Error: 0

Fixed submission:

#include <bits/stdc++.h> // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Jun  7 21:10:13 JST 2020
 **/

int get_msb(long long x) {
  assert(x != 0);
  return 63 - __builtin_clzll(x);
}
int get_lsb(long long x) {
  assert(x != 0);
  return __builtin_ctzll(x);
}

void GaussJordan(std::vector<Int> &A, bool is_extended = false) {
  Int rank = 0;
  for (Int col = 0; col < 62; ++col) {
    if (is_extended && col == 62 - 1)
      break;
    Int pivot = -1;
    for (Int row = rank; row < A.size(); ++row) {
      if (A[row] >> col & 1) {
        pivot = row;
        break;
      }
    }
    if (pivot == -1)
      continue;
    std::swap(A[pivot], A[rank]);
    for (Int row = 0; row < A.size(); ++row) {
      if (row != rank && (A[row] >> col & 1))
        A[row] ^= A[rank];
    }
    ++rank;
  }
}
void solve() {
  Int n;
  std::cin >> n;
  std::vector<Int> a(n);
  REP(i, n) std::cin >> a[i];
  std::string s;
  std::cin >> s;
  std::vector<Int> acc;
  for (Int i = n - 1; i >= 0; i--) {
    if (s[i] == '0') {
      acc.push_back(a[i]);
      GaussJordan(acc);
    } else {
      while (a[i]) {
        Int ms = get_msb(a[i]);
        bool ok = false;
        for (Int x : acc) {
          if (get_msb(x) == ms) {
            a[i] ^= x;
            ok = true;
            break;
          }
        }
        if (!ok) {
          std::cout << 1 << "\\n";
          return;
        }
      }
    }
  }
  std::cout << 0 << "\\n";
}
signed main() {
  Int T;
  std::cin >> T;
  while (T--)
    solve();
}