結果
| 問題 | No.184 たのしい排他的論理和(HARD) |
| コンテスト | |
| ユーザー |
not_522
|
| 提出日時 | 2015-08-20 00:14:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 338 ms / 5,000 ms |
| コード長 | 6,408 bytes |
| コンパイル時間 | 1,738 ms |
| コンパイル使用メモリ | 167,324 KB |
| 実行使用メモリ | 15,744 KB |
| 最終ジャッジ日時 | 2024-07-04 12:02:25 |
| 合計ジャッジ時間 | 8,639 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
namespace arithmetic {
template<typename T> class Addition {
public:
template<typename V> T operator+(const V& v) const {
return T(static_cast<const T&>(*this)) += v;
}
};
template<typename T> class Subtraction {
public:
template<typename V> T operator-(const V& v) const {
return T(static_cast<const T&>(*this)) -= v;
}
};
template<typename T> class Multiplication {
public:
template<typename V> T operator*(const V& v) const {
return T(static_cast<const T&>(*this)) *= v;
}
};
template<typename T> class Division {
public:
template<typename V> T operator/(const V& v) const {
return T(static_cast<const T&>(*this)) /= v;
}
};
template<typename T> class Modulus {
public:
template<typename V> T operator%(const V& v) const {
return T(static_cast<const T&>(*this)) %= v;
}
};
}
template<typename T> class IndivisibleArithmetic : public arithmetic::Addition<T>, public arithmetic::Subtraction<T>, public arithmetic::Multiplication<T> {};
template<typename T> class Arithmetic : public IndivisibleArithmetic<T>, public arithmetic::Division<T> {};
template<typename T> class Bitwise {
public:
T operator&(const T& v) const {
T res(static_cast<const T&>(*this));
return res &= v;
}
T operator|(const T& v) const {
T res(static_cast<const T&>(*this));
return res |= v;
}
T operator^(const T& v) const {
T res(static_cast<const T&>(*this));
return res ^= v;
}
};
template<typename T> int least_bit(T n) {
static_assert(sizeof(T) == 4 || sizeof(T) == 8, "unsupported size");
if (sizeof(T) == 4) return __builtin_ffs(n) - 1;
if (sizeof(T) == 8) return __builtin_ffsll(n) - 1;
}
template<typename T> int most_bit(T n) {
static_assert(sizeof(T) == 4 || sizeof(T) == 8, "unsupported size");
if (sizeof(T) == 4) return n ? 31 - __builtin_clz(n) : -1;
if (sizeof(T) == 8) return n ? 63 - __builtin_clzll(n) : -1;
}
template<typename T> int count_bit(T n) {
static_assert(sizeof(T) == 4 || sizeof(T) == 8, "unsupported size");
if (sizeof(T) == 4) return __builtin_popcount(n);
if (sizeof(T) == 8) return __builtin_popcountll(n);
}
class Bitset : public Bitwise<Bitset> {
private:
int arraySize(int n) const {
return (n + 63) / 64;
}
void resize(int n) {
val.resize(arraySize(n) + 1);
}
public:
vector<unsigned long long> val;
class reference {
private:
friend class Bitset;
vector<unsigned long long>::iterator val;
int pos;
reference(vector<unsigned long long>::iterator val, int pos) : val(val), pos(pos) {}
public:
reference operator=(const reference& r) {
if ((bool)r) *val |= 1ull << pos;
else *val &= ~(1ull << pos);
return *this;
}
reference operator=(const bool b) {
if (b) *val |= 1ull << pos;
else *val &= ~(1ull << pos);
return *this;
}
operator bool() const {
return *val >> pos & 1;
}
};
Bitset() {}
Bitset(int n) : val(arraySize(n), 0) {}
reference operator[](int n) {
if (arraySize(n) >= (int)val.size()) resize(n);
return reference(val.begin() + n / 64, n % 64);
}
bool operator[](int n) const {
if (arraySize(n) >= (int)val.size()) return false;
return val[n / 64] >> n % 64 & 1;
}
Bitset operator&=(const Bitset& b) {
if (val.size() < b.val.size()) val.resize(b.val.size());
for (size_t i = 0; i < val.size(); ++i) {
if (i < b.val.size()) val[i] &= b.val[i];
}
return *this;
}
Bitset operator|=(const Bitset& b) {
if (val.size() < b.val.size()) val.resize(b.val.size());
for (size_t i = 0; i < val.size(); ++i) {
if (i < b.val.size()) val[i] |= b.val[i];
}
return *this;
}
Bitset operator^=(const Bitset& b) {
if (val.size() < b.val.size()) val.resize(b.val.size());
for (size_t i = 0; i < val.size(); ++i) {
if (i < b.val.size()) val[i] ^= b.val[i];
}
return *this;
}
int count() {
return accumulate(val.begin(), val.end(), 0, [](int a, unsigned long long b){return a + count_bit(b);});
}
bool parity() {
return accumulate(val.begin(), val.end(), 0, [](int a, unsigned long long b){return a ^ __builtin_parityll(b);});
}
int size() const {
return val.size() * 64;
}
};
class BitsetMatrix : public Arithmetic<BitsetMatrix> {
private:
vector<Bitset> val;
public:
BitsetMatrix(int n) : val(n) {}
BitsetMatrix(int n, int m) : val(n, Bitset(m)) {}
Bitset& operator[](int n) {
return val[n];
}
const Bitset& operator[](int n) const {
return val[n];
}
BitsetMatrix operator+=(const BitsetMatrix& m) {
for (int i = 0; i < size(); ++i) val[i] ^= m[i];
return *this;
}
BitsetMatrix operator-=(const BitsetMatrix& m) {
for (int i = 0; i < size(); ++i) val[i] ^= m[i];
return *this;
}
BitsetMatrix operator*=(const BitsetMatrix& _m) {
BitsetMatrix m = _m.transpose(), res(size());
for (int i = 0; i < size(); ++i) res[i] = *this * m[i];
return *this = res.transpose();
}
BitsetMatrix operator*(const BitsetMatrix& m) const {
auto res(static_cast<const BitsetMatrix&>(*this));
return res *= m;
}
Bitset operator*(const Bitset& v) const {
Bitset res(size());
for (int i = 0; i < size(); ++i) res[i] = (val[i] & v).parity();
return res;
}
BitsetMatrix transpose() const {
BitsetMatrix res(size());
for (int i = 0; i < size(); ++i) {
for (int j = 0; j < size(); ++j) {
res[i][j] = (*this)[j][i];
}
}
return res;
}
int size() const {
return val.size();
}
int rank() const {
int n = 0, r = 0;
BitsetMatrix mat = *this;
for (int i = 0; i < size(); ++i) n = max(n, mat[i].size());
for (int i = 0; i < n; ++i) {
int p = r;
for (int j = r + 1; j < size(); ++j) {
if (abs(mat[j][i]) > abs(mat[p][i])) p = j;
}
if (mat[p][i] == 0) continue;
swap(mat[r], mat[p]);
for (int j = r + 1; j < size(); ++j) {
if (!mat[j][i]) continue;
mat[j] ^= mat[r];
}
++r;
if (r == size()) break;
}
return r;
}
};
int main() {
int n;
cin >> n;
BitsetMatrix m(n);
for (int i = 0; i < n; ++i) {
long long a;
cin >> a;
for (int j = 0; a; ++j, a /= 2) m[i][j] = a % 2;
}
cout << (1ll << m.rank()) << endl;
}
not_522