結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー 👑 emthrmemthrm
提出日時 2020-01-04 12:54:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 3,258 bytes
コンパイル時間 2,614 ms
コンパイル使用メモリ 201,580 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-17 18:05:46
合計ジャッジ時間 4,755 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 37 ms
4,376 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 29 ms
4,376 KB
testcase_11 AC 21 ms
4,380 KB
testcase_12 AC 43 ms
4,376 KB
testcase_13 AC 46 ms
4,376 KB
testcase_14 AC 27 ms
4,380 KB
testcase_15 AC 50 ms
4,376 KB
testcase_16 AC 43 ms
4,380 KB
testcase_17 AC 45 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 52 ms
4,376 KB
testcase_22 AC 52 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 32 ms
4,380 KB
testcase_29 AC 44 ms
4,376 KB
testcase_30 AC 38 ms
4,380 KB
testcase_31 AC 33 ms
4,380 KB
testcase_32 AC 41 ms
4,380 KB
testcase_33 AC 50 ms
4,376 KB
testcase_34 AC 50 ms
4,376 KB
testcase_35 AC 51 ms
4,380 KB
testcase_36 AC 51 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
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 dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {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; }
int popcount(int val) { return __builtin_popcount(val); }
int popcountll(ll val) { return __builtin_popcountll(val); }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

const int COL = 61;
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 &rhs) {
    m = rhs.m;
    n = rhs.n;
    dat.resize(m);
    REP(i, m) dat[i] = rhs[i];
    return *this;
  }

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

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

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

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

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

int gauss_jordan(BinaryMatrix &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() {
  int n; cin >> n;
  BinaryMatrix mat(n);
  REP(i, n) {
    ll a; cin >> a;
    mat[i] = bitset<COL>(a);
  }
  int rank = gauss_jordan(mat);
  ll ans = 1;
  REP(_, rank) ans <<= 1;
  cout << ans << '\n';
  return 0;
}
0