結果
問題 | No.184 たのしい排他的論理和(HARD) |
ユーザー | not_522 |
提出日時 | 2015-08-19 23:37:43 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,292 bytes |
コンパイル時間 | 1,402 ms |
コンパイル使用メモリ | 167,284 KB |
実行使用メモリ | 85,280 KB |
最終ジャッジ日時 | 2024-07-04 12:01:50 |
合計ジャッジ時間 | 8,275 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | TLE | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
ソースコード
#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);}); } }; 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 = size(), res = 0; BitsetMatrix mat = *this; for (int i = 0; i < n; ++i) { int p = i; for (int j = i + 1; j < n; ++j) { if (abs(mat[j][i]) > abs(mat[p][i])) p = j; } swap(mat[i], mat[p]); if (mat[i][i] == 0) continue; else ++res; for (int j = 0; j < n; ++j) { if (i == j) continue; if (!mat[j][i]) continue; mat[j] ^= mat[i]; } } return res; } }; 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; }