結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー 👑 emthrmemthrm
提出日時 2019-03-30 02:30:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 3,150 bytes
コンパイル時間 1,388 ms
コンパイル使用メモリ 124,940 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 17:49:20
合計ジャッジ時間 3,735 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 37 ms
4,376 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 28 ms
4,380 KB
testcase_11 AC 21 ms
4,376 KB
testcase_12 AC 43 ms
4,380 KB
testcase_13 AC 47 ms
4,376 KB
testcase_14 AC 27 ms
4,376 KB
testcase_15 AC 50 ms
4,376 KB
testcase_16 AC 42 ms
4,376 KB
testcase_17 AC 45 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 52 ms
4,376 KB
testcase_22 AC 52 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 32 ms
4,376 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 40 ms
4,380 KB
testcase_33 AC 50 ms
4,380 KB
testcase_34 AC 50 ms
4,376 KB
testcase_35 AC 51 ms
4,380 KB
testcase_36 AC 51 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
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()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
const int MAX = 61;
struct BinaryMatrix {
  int m, n;

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

  BinaryMatrix pow(long long 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<MAX> &operator[](const int idx) const { return dat[idx]; }
  inline bitset<MAX> &operator[](const int idx) { return dat[idx]; }

  BinaryMatrix &operator=(const BinaryMatrix &rhs) {
    m = rhs.m;
    n = rhs.n;
    dat.clear();
    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<MAX> > 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() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  BinaryMatrix mat(n);
  REP(i, n) {
    long long a; cin >> a;
    mat[i] = bitset<MAX>(a);
  }
  int rank = gauss_jordan(mat);
  long long ans = 1;
  REP(i, rank) ans *= 2;
  cout << ans << '\n';
  return 0;
}
0