結果
| 問題 |
No.184 たのしい排他的論理和(HARD)
|
| コンテスト | |
| ユーザー |
hashiryo
|
| 提出日時 | 2019-04-10 13:32:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 88 ms / 5,000 ms |
| コード長 | 2,790 bytes |
| コンパイル時間 | 901 ms |
| コンパイル使用メモリ | 99,444 KB |
| 実行使用メモリ | 9,600 KB |
| 最終ジャッジ日時 | 2024-07-04 12:25:53 |
| 合計ジャッジ時間 | 3,842 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>
#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const long long INF = INT_MAX;
const ll MOD = 1000000007;
ll pow_mod(ll x,int n){
if(!n)return 1;
ll res=pow_mod(x*x%MOD,n/2);
if(n&1)res = res*x%MOD;
return res%MOD;
}
const int MAX_ROW = 500; // to be set appropriately
const int MAX_COL = 100010; // 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];}
};
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) {
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;
return rank;
}
ostream &operator<<(ostream &os, BitMatrix &v) {
os << "[";
for (int i = 0; i < v.H; i++){
if (i > 0) os <<endl<< " ";
os << "[";
for (int j = 0; j < v.W; os << v[i][j++])
if (j > 0) os << " ";
os << "]";
}
os << "]";
return os;
}
int main(){
int N;cin>>N;
BitMatrix B(63,N);
repeat(i,N){
ll A;cin>>A;
repeat(j,63){
B[j][i] = (A>>j)&1;
}
}
cout<<(1ll<<GaussJordan(B))<<endl;
return 0;
}
hashiryo