結果

問題 No.183 たのしい排他的論理和(EASY)
ユーザー koyumeishikoyumeishi
提出日時 2015-04-17 03:33:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,443 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 81,172 KB
実行使用メモリ 6,292 KB
最終ジャッジ日時 2023-09-17 21:27:25
合計ジャッジ時間 1,981 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

long long extgcd(long long a, long long b, long long &x, long long &y){
	long long d=a;
	if(b!=0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

long long mod_inverse(long long a, long long m){
	long long x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}


// A[n*p] * X[p*m] = B[n*m]
template<class T = int>
int gaussian_elimination_with_mod(vector<vector<T>>& A, vector<vector<T>>& B, int n, int p, int m, const T mod){
	vector<vector<T>> V( n, vector<T>(p+m, 0) );
	for(int i=0; i<n; i++)
		for(int j=0; j<p; j++) V[i][j] = A[i][j];
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++) V[i][j+p] = B[i][j];


	int rank = 0;
	int row = 0;

	vector<int> left(n, -1);

	//foward
	for(int col=0; col<n && row<n; col++){
		//pivot
		T val = abs( V[row][col] );
		int pivot = row;
		for(int j=row+1; j<n; j++){
			if(val < abs( V[j][col] )){
				val = abs( V[j][col] );
				pivot = j;
			}
		}
		if(pivot != row) swap(V[row], V[pivot]);

		if(val == 0) continue;

		T inv = mod_inverse(val, mod);
		for(int j=row+1; j<n; j++){
			T c = (V[j][col] * inv + mod) % mod;
			for(int k=col; k<p+m; k++) V[j][k] = ((V[j][k] - V[row][k] * c) % mod + mod) % mod;
		}

		left[row] = col;
		row++;
		rank++;
	}

	return rank;
/*
	//backward
	for(int i=n-1; i>=0; i--){
		bool zero = true;
		bool valid = true;
		for(int col=0; col<n; col++) if(V[i][col] != 0) zero = false;
		for(int col = n; zero && col<p+m; col++) if(V[i][col] != 0) valid = false;

		if(valid == false) return -1;	//no solution

		if(left[i] == -1) continue;

		T inv = mod_inverse(V[i][ left[i] ], mod);
		for(int j=left[i]; j<m+p; j++) V[i][j] = (V[i][j] * inv) % mod;

		for(int j=i-1; j>=0; j--){
			for(int k=0; k<m+p; k++){
				V[j][k] = ( (V[j][k] - V[j][i] * V[i][k]) % mod + mod ) % mod;
			}
		}
	}

	//return V;
	return rank;
*/
}

int main(){
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}

	vector<vector<int>> A(n, vector<int>(64, 0));
	for(int i=0; i<n; i++){
		for(long long j=0; j<64; j++){
			A[i][j] = (a[i] >> j) & 1LL;
		}
	}

	vector<vector<int>> B(64);

	long long rank = gaussian_elimination_with_mod<int>(A,B, n,64,0, 2);
	cerr << rank << endl;
	cout << (1LL<<rank) << endl;

	return 0;
}
0