結果
問題 | No.184 たのしい排他的論理和(HARD) |
ユーザー | hashiryo |
提出日時 | 2020-04-22 23:17:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,270 bytes |
コンパイル時間 | 2,199 ms |
コンパイル使用メモリ | 188,272 KB |
実行使用メモリ | 55,552 KB |
最終ジャッジ日時 | 2024-07-04 12:46:00 |
合計ジャッジ時間 | 6,327 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 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 | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 115 ms
40,192 KB |
testcase_09 | AC | 26 ms
11,008 KB |
testcase_10 | AC | 89 ms
31,360 KB |
testcase_11 | AC | 63 ms
23,296 KB |
testcase_12 | AC | 134 ms
46,336 KB |
testcase_13 | AC | 145 ms
49,792 KB |
testcase_14 | AC | 83 ms
29,952 KB |
testcase_15 | AC | 155 ms
53,760 KB |
testcase_16 | AC | 131 ms
45,312 KB |
testcase_17 | AC | 141 ms
48,640 KB |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 84 ms
55,552 KB |
testcase_21 | AC | 162 ms
55,424 KB |
testcase_22 | AC | 162 ms
55,424 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 | 2 ms
5,376 KB |
testcase_28 | AC | 99 ms
34,688 KB |
testcase_29 | AC | 138 ms
47,744 KB |
testcase_30 | AC | 121 ms
42,624 KB |
testcase_31 | AC | 105 ms
37,248 KB |
testcase_32 | AC | 130 ms
45,824 KB |
testcase_33 | AC | 159 ms
54,016 KB |
testcase_34 | AC | 156 ms
53,376 KB |
testcase_35 | AC | 159 ms
55,148 KB |
testcase_36 | AC | 159 ms
54,784 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, 60); 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; }