結果

問題 No.183 たのしい排他的論理和(EASY)
ユーザー 👑 emthrmemthrm
提出日時 2020-03-16 01:52:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 2,960 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 195,172 KB
最終ジャッジ日時 2025-01-09 07:12:56
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <int COL = 2500>
struct BinaryMatrix {
  int m, n;

  BinaryMatrix(int m, int n = COL, bool def = false) : m(m), n(n), dat(m, bitset<COL>(0)) {
    if (def) {
      REP(i, m) REP(j, n) dat[i][j] = 1;
    }
  }

  BinaryMatrix pow(ll exponent) {
    BinaryMatrix tmp = *this, res(n, n);
    REP(i, n) res[i][i] = 1;
    while (exponent > 0) {
      if (exponent & 1) res *= tmp;
      tmp *= tmp;
      exponent >>= 1;
    }
    return res;
  }

  inline const bitset<COL> &operator[](const int idx) const { return dat[idx]; }
  inline bitset<COL> &operator[](const int idx) { return dat[idx]; }

  BinaryMatrix &operator=(const BinaryMatrix &x) {
    m = x.m;
    n = x.n;
    dat.resize(m);
    REP(i, m) dat[i] = x[i];
    return *this;
  }

  BinaryMatrix &operator+=(const BinaryMatrix &x) {
    REP(i, m) dat[i] ^= x[i];
    return *this;
  }

  BinaryMatrix &operator*=(const BinaryMatrix &x) {
    int height = m, width = x.n;
    BinaryMatrix t_x(x.n, x.m), res(height, width);
    REP(i, x.n) REP(j, x.m) t_x[i][j] = x[j][i];
    REP(i, height) REP(j, width) res[i][j] = ((dat[i] & t_x[j]).count() & 1);
    *this = res;
    return *this;
  }

  BinaryMatrix operator+(const BinaryMatrix &x) const { return BinaryMatrix(*this) += x; }

  BinaryMatrix operator*(const BinaryMatrix &x) const { return BinaryMatrix(*this) *= x; }

private:
  vector<bitset<COL> > dat;
};

template <int COL>
int gauss_jordan(BinaryMatrix<COL> &mat, bool is_extended = false) {
  int rank = 0;
  REP(col, mat.n) {
    if (is_extended && col == mat.n - 1) break;
    int pivot = -1;
    FOR(row, rank, mat.m) {
      if (mat[row][col]) {
        pivot = row;
        break;
      }
    }
    if (pivot == -1) continue;
    swap(mat[rank], mat[pivot]);
    REP(row, mat.m) {
      if (row != rank && mat[row][col]) mat[row] ^= mat[rank];
    }
    ++rank;
  }
  return rank;
}

int main() {
  const int X = 60;
  int n; cin >> n;
  BinaryMatrix<X> mat(n);
  REP(i, n) {
    ll a; cin >> a;
    mat[i] = a;
  }
  int rank = gauss_jordan(mat);
  ll ans = 1;
  REP(_, rank) ans <<= 1;
  cout << ans << '\n';
  return 0;
}
0