結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー hiro71687k
提出日時 2023-07-18 18:17:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 3,094 bytes
コンパイル時間 4,617 ms
コンパイル使用メモリ 253,080 KB
最終ジャッジ日時 2025-02-15 15:37:37
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=1000000007;
ld inf=10000999999999900;
const int MAX_ROW = 100002; // to be set appropriately
const int MAX_COL = 62; // to be set appropriately
struct BitMatrix {
int H, W;
bitset<MAX_COL> val[MAX_ROW];
BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};
ostream& operator << (ostream& s, BitMatrix A) {
s << endl;
for (int i = 0; i < A.H; ++i) {
for (int j = 0; j < A.W; ++j) {
s << A[i][j] << ", ";
}
s << endl;
}
return s;
}
inline BitMatrix operator * (BitMatrix A, BitMatrix B) {
BitMatrix R(A.H, B.W);
BitMatrix tB(B.W, B.H);
for (int i = 0; i < tB.H; ++i) for (int j = 0; j < tB.W; ++j) tB[i][j] = B[j][i];
for (int i = 0; i < R.H; ++i) for (int j = 0; j < R.W; ++j) R[i][j] = ((A[i] & tB[j]).count() & 1);
return R;
}
inline BitMatrix pow(BitMatrix A, long long n) {
BitMatrix R(A.H, A.H);
for (int i = 0; i < A.H; ++i) R[i][i] = 1;
while (n > 0) {
if (n & 1) R = R * A;
A = A * A;
n >>= 1;
}
return R;
}
int GaussJordan(BitMatrix &A, bool is_extended = false) {
int rank = 0;
for (int col = 0; col < A.W; ++col) {
if (is_extended && col == A.W - 1) break;
int pivot = -1;
for (int row = rank; row < A.H; ++row) {
if (A[row][col]) {
pivot = row;
break;
}
}
if (pivot == -1) continue;
swap(A[pivot], A[rank]);
for (int row = 0; row < A.H; ++row) {
if (row != rank && A[row][col]) A[row] ^= A[rank];
}
++rank;
}
return rank;
}
int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
int m = A.H, n = A.W;
BitMatrix M(m, n + 1);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
M[i][n] = b[i];
}
int rank = GaussJordan(M, true);
// check if it has no solution
for (int row = rank; row < m; ++row) if (M[row][n]) return -1;
// answer
res.assign(n, 0);
for (int i = 0; i < rank; ++i) res[i] = M[i][n];
return rank;
}
const int MOD = 998244353;
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
int N, M; cin >> N;
M=61;
BitMatrix A(N, M);
vector<ll>two(61,1);
for (ll i = 1; i < two.size(); i++)
{
two[i]=two[i-1]*2;
}
for (int i = 0; i < N; ++i) {
ll x;
cin >> x;
for (ll j = 0; j <=60; j++)
{
if (two[j]&x)
{
A[i][j]=1;
}else{
A[i][j]=0;
}
}
}
vector<int> res;
int r = GaussJordan(A);
cout << two[r] << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0