結果
問題 | No.184 たのしい排他的論理和(HARD) |
ユーザー | not_522 |
提出日時 | 2015-08-19 23:42:08 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,428 bytes |
コンパイル時間 | 1,470 ms |
コンパイル使用メモリ | 169,072 KB |
実行使用メモリ | 15,744 KB |
最終ジャッジ日時 | 2024-07-04 12:01:09 |
合計ジャッジ時間 | 8,342 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 238 ms
12,032 KB |
testcase_09 | AC | 51 ms
6,944 KB |
testcase_10 | AC | 182 ms
9,856 KB |
testcase_11 | AC | 131 ms
7,936 KB |
testcase_12 | AC | 278 ms
13,568 KB |
testcase_13 | AC | 301 ms
14,336 KB |
testcase_14 | AC | 170 ms
9,472 KB |
testcase_15 | AC | 326 ms
15,232 KB |
testcase_16 | AC | 273 ms
13,184 KB |
testcase_17 | AC | 292 ms
13,952 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 1 ms
6,944 KB |
testcase_20 | AC | 84 ms
14,196 KB |
testcase_21 | AC | 338 ms
15,608 KB |
testcase_22 | AC | 338 ms
15,744 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 201 ms
10,624 KB |
testcase_29 | AC | 285 ms
13,952 KB |
testcase_30 | AC | 248 ms
12,544 KB |
testcase_31 | AC | 213 ms
11,264 KB |
testcase_32 | AC | 267 ms
13,312 KB |
testcase_33 | AC | 329 ms
15,232 KB |
testcase_34 | AC | 325 ms
15,232 KB |
testcase_35 | AC | 331 ms
15,616 KB |
testcase_36 | AC | 332 ms
15,616 KB |
ソースコード
#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, res = 0; BitsetMatrix mat = *this; for (int i = 0; i < size(); ++i) n = max(n, mat[i].size()); for (int i = 0; i < min(n, size()); ++i) { int p = i; for (int j = i + 1; j < size(); ++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 < size(); ++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; }