結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー furafura
提出日時 2020-08-08 02:35:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 5,000 ms
コード長 2,635 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 205,244 KB
実行使用メモリ 24,196 KB
最終ジャッジ日時 2023-09-17 18:29:03
合計ジャッジ時間 6,497 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 116 ms
18,136 KB
testcase_09 AC 24 ms
6,200 KB
testcase_10 AC 85 ms
14,428 KB
testcase_11 AC 60 ms
11,204 KB
testcase_12 AC 133 ms
20,580 KB
testcase_13 AC 143 ms
21,896 KB
testcase_14 AC 79 ms
13,896 KB
testcase_15 AC 156 ms
23,464 KB
testcase_16 AC 130 ms
20,196 KB
testcase_17 AC 139 ms
21,184 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 70 ms
24,084 KB
testcase_21 AC 160 ms
24,080 KB
testcase_22 AC 162 ms
24,196 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 95 ms
15,640 KB
testcase_29 AC 137 ms
21,236 KB
testcase_30 AC 117 ms
18,860 KB
testcase_31 AC 101 ms
16,876 KB
testcase_32 AC 127 ms
20,456 KB
testcase_33 AC 156 ms
23,740 KB
testcase_34 AC 155 ms
23,428 KB
testcase_35 AC 163 ms
23,872 KB
testcase_36 AC 158 ms
23,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class R>
class matrix{
	vector<vector<R>> a;
public:
	matrix(int n):a(n,vector<R>(n)){}
	matrix(int m,int n):a(m,vector<R>(n)){}

	matrix& operator+=(const matrix& A){
		assert(h()==A.h() && w()==A.w());
		int m=h(),n=w();
		rep(i,m) rep(j,n) (*this)[i][j]+=A[i][j];
		return *this;
	}
	matrix& operator-=(const matrix& A){
		assert(h()==A.h() && w()==A.w());
		int m=h(),n=w();
		rep(i,m) rep(j,n) (*this)[i][j]-=A[i][j];
		return *this;
	}
	matrix& operator*=(const matrix& A){
		assert(w()==A.h());
		int m=h(),n=w(),l=A.w();
		matrix B(m,l);
		rep(i,m) rep(j,l) rep(k,n) B[i][j]+=(*this)[i][k]*A[k][j];
		swap(*this,B);
		return *this;
	}
	matrix operator+(const matrix& A)const{ return matrix(*this)+=A; }
	matrix operator-(const matrix& A)const{ return matrix(*this)-=A; }
	matrix operator*(const matrix& A)const{ return matrix(*this)*=A; }
	const vector<R>& operator[](int i)const{ return a[i]; }
	vector<R>& operator[](int i){ return a[i]; }

	vector<R> operator*(const vector<R>& v)const{
		assert(w()==v.size());
		int m=h(),n=w();
		vector<R> res(m);
		rep(i,m) rep(j,n) res[i]+=(*this)[i][j]*v[j];
		return res;
	}

	int h()const{ return a.size(); }
	int w()const{ return a.empty()?0:a[0].size(); }

	static matrix identity(int n){
		matrix I(n);
		rep(i,n) I[i][i]=R{1};
		return I;
	}
};

class F2{
	bool x;
public:
	F2():x(false){}
	F2(long long n){ assert(n==0||n==1); x=(n==1); }
	F2& operator+=(const F2& a){ x=(x!=a.x); return *this; }
	F2& operator-=(const F2& a){ return (*this)+=a; }
	F2& operator*=(const F2& a){ x=(x&&a.x); return *this; }
	F2& operator/=(const F2& a){ assert(a.x); return *this; }
	F2 operator+(const F2& a)const{ return F2(*this)+=a; }
	F2 operator-(const F2& a)const{ return F2(*this)-=a; }
	F2 operator*(const F2& a)const{ return F2(*this)*=a; }
	F2 operator/(const F2& a)const{ return F2(*this)/=a; }
	bool operator==(const F2& a)const{ return x==a.x; }
	bool operator!=(const F2& a)const{ return !((*this)==a); }
	int to_int()const{ return x; }
};

int matrix_rank(matrix<F2> A){
	int m=A.h(),n=A.w(),r=0;
	rep(j,n){
		int piv;
		for(piv=r;piv<m;piv++) if(A[piv][j]==1) break;
		if(piv==m) continue;
		if(piv!=r){
			rep(k,n) swap(A[piv][k],A[r][k]);
		}
		for(int i=r+1;i<m;i++) if(A[i][j]==1) {
			for(int k=j;k<n;k++) A[i][k]-=A[r][k];
		}
		r++;
	}
	return r;
}

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	matrix<F2> A(n,61);
	rep(i,n) rep(j,61) A[i][j]=a[i]>>j&1;
	printf("%lld\n",1LL<<matrix_rank(A));

	return 0;
}
0