結果
問題 | No.184 たのしい排他的論理和(HARD) |
ユーザー | hashiryo |
提出日時 | 2020-04-22 23:18:45 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 158 ms / 5,000 ms |
コード長 | 6,271 bytes |
コンパイル時間 | 1,907 ms |
コンパイル使用メモリ | 188,140 KB |
実行使用メモリ | 60,220 KB |
最終ジャッジ日時 | 2024-07-04 12:46:06 |
合計ジャッジ時間 | 5,896 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 108 ms
43,392 KB |
testcase_09 | AC | 23 ms
11,520 KB |
testcase_10 | AC | 81 ms
33,920 KB |
testcase_11 | AC | 60 ms
25,216 KB |
testcase_12 | AC | 128 ms
50,176 KB |
testcase_13 | AC | 137 ms
53,888 KB |
testcase_14 | AC | 78 ms
32,128 KB |
testcase_15 | AC | 150 ms
58,240 KB |
testcase_16 | AC | 126 ms
49,024 KB |
testcase_17 | AC | 136 ms
52,864 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 85 ms
60,220 KB |
testcase_21 | AC | 154 ms
60,032 KB |
testcase_22 | AC | 158 ms
60,160 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 1 ms
5,376 KB |
testcase_28 | AC | 93 ms
37,632 KB |
testcase_29 | AC | 135 ms
51,584 KB |
testcase_30 | AC | 113 ms
46,080 KB |
testcase_31 | AC | 96 ms
40,192 KB |
testcase_32 | AC | 128 ms
49,536 KB |
testcase_33 | AC | 155 ms
58,624 KB |
testcase_34 | AC | 148 ms
57,856 KB |
testcase_35 | AC | 156 ms
59,648 KB |
testcase_36 | AC | 152 ms
59,392 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { return *this *= p.inverse(); } ModInt operator-() const { return ModInt() - *this; } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b) t = a / b, swap(a -= t * b, b), swap(u -= t * v, v); return ModInt(u); } ModInt pow(int64_t e) const { ModInt ret(1); for (ModInt b = *this; e; e >>= 1, b *= b) if (e & 1) ret *= b; return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int modulo() { return mod; } }; struct BitMatrix { private: vector<vector<short>> a; public: BitMatrix() {} BitMatrix(size_t n, size_t m) : a(n, vector<short>(m, 0)) {} BitMatrix(size_t n) : BitMatrix(n, n) {} inline const vector<short> &operator[](size_t k) const { return a[k]; } inline vector<short> &operator[](size_t k) { return a[k]; } size_t height() const { return a.size(); } size_t width() const { return a[0].size(); } static BitMatrix I(size_t n) { BitMatrix mat(n); for (int i = 0; i < n; i++) mat[i][i] = 1; return mat; } BitMatrix operator+(const BitMatrix &b) const { size_t n = height(), m = width(); BitMatrix c(n, m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) c[i][j] = (*this)[i][j] ^ b[i][j]; return c; } BitMatrix operator*(const BitMatrix &b) const { if (width() <= 64) return mul<64>(b); if (width() <= 2600) return mul<2600>(b); return mul<100010>(b); } BitMatrix &operator+=(const BitMatrix &b) { return *this = (*this) + b; } BitMatrix &operator*=(const BitMatrix &b) { return *this = (*this) * b; } bool operator==(const BitMatrix &b) const { return a == b.a; } BitMatrix pow(uint64_t e) const { BitMatrix ret = I(height()); for (BitMatrix base = *this; e; e >>= 1, base *= base) if (e & 1) ret *= base; return ret; } static pair<BitMatrix, BitMatrix> Gauss_Jordan(const BitMatrix &a, const BitMatrix &b) { if (a.width() + b.width() <= 64) return gauss_jordan_content<64>(a, b); if (a.width() + b.width() <= 2600) return gauss_jordan_content<2600>(a, b); return gauss_jordan_content<100010>(a, b); } static pair<vector<int>, vector<vector<int>>> linear_equations( const BitMatrix &a, const vector<int> &b) { int n = a.height(), m = a.width(); BitMatrix B(n, 1); for (int i = 0; i < n; i++) B[i][0] = b[i]; auto p = Gauss_Jordan(a, B); vector<int> jdx(n, -1), idx(m, -1); for (int i = 0, j; i < n; i++) { for (j = 0; j < m; j++) { if (p.first[i][j]) { jdx[i] = j, idx[j] = i; break; } } if (j == m && p.second[i][0]) return make_pair(vector<int>(), vector<vector<int>>()); // no solutions } vector<int> c(m); vector<vector<int>> d; for (int j = 0; j < m; j++) { if (idx[j] != -1) c[j] = p.second[idx[j]][0]; else { vector<int> v(m); v[j] = 1; for (int i = 0; i < n; i++) if (jdx[i] != -1) v[jdx[i]] = p.first[i][j]; d.push_back(v); } } return make_pair(c, d); } int rank() const { int n = height(), m = width(); BitMatrix b(n, 0); BitMatrix p = Gauss_Jordan(*this, b).first; for (int i = 0, j; i < n; i++) { for (j = 0; j < m; j++) if (p[i][j] != 0) break; if (j == m) return i; } return n; } private: template <size_t SIZE> BitMatrix mul(const BitMatrix &b) const { size_t n = height(), m = width(), l = b.width(); assert(m == b.height()); vector<bitset<SIZE>> tb(l); for (int i = 0; i < l; ++i) for (int j = 0; j < m; ++j) tb[i][j] = b[j][i]; BitMatrix c(n, l); for (int i = 0; i < n; i++) { bitset<SIZE> abit; for (int k = 0; k < m; k++) abit[k] = (*this)[i][k]; for (int j = 0; j < l; j++) c[i][j] = ((abit & tb[j]).count() & 1); } return c; } template <size_t SIZE> static pair<BitMatrix, BitMatrix> gauss_jordan_content(const BitMatrix &a, const BitMatrix &b) { size_t n = a.height(), m = a.width(), l = b.width(); vector<bitset<SIZE>> c(n); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) c[i][j] = a[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < l; j++) c[i][j + m] = b[i][j]; int d = 0; for (int j = 0; j < m; j++) { int p = d; for (int i = d + 1; i < n; i++) if (c[i][j]) p = i; if (!c[p][j]) continue; swap(c[p], c[d]); for (int i = 0; i < n; i++) if (i != d && c[i][j]) c[i] ^= c[d]; d++; } BitMatrix reta(n, m), retb(n, l); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) reta[i][j] = c[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < l; j++) retb[i][j] = c[i][j + m]; return make_pair(reta, retb); } }; signed main() { cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; BitMatrix A(N, 61); for (int i = 0; i < N; i++) { long long a; cin >> a; for (int j = 0; j <= 60; j++) A[i][j] = (a >> j) & 1; } cout << (1ll << A.rank()) << endl; return 0; }