結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー koyumeishikoyumeishi
提出日時 2015-04-17 03:41:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,452 ms / 5,000 ms
コード長 2,464 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 81,264 KB
実行使用メモリ 62,200 KB
最終ジャッジ日時 2023-09-17 16:31:10
合計ジャッジ時間 27,064 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1,029 ms
44,700 KB
testcase_09 AC 206 ms
11,708 KB
testcase_10 AC 782 ms
34,996 KB
testcase_11 AC 555 ms
25,756 KB
testcase_12 AC 1,198 ms
51,528 KB
testcase_13 AC 1,303 ms
55,568 KB
testcase_14 AC 738 ms
33,148 KB
testcase_15 AC 1,418 ms
60,188 KB
testcase_16 AC 1,168 ms
50,676 KB
testcase_17 AC 1,267 ms
54,544 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 162 ms
62,028 KB
testcase_21 AC 1,448 ms
62,200 KB
testcase_22 AC 1,452 ms
61,892 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 862 ms
38,412 KB
testcase_29 AC 1,211 ms
53,160 KB
testcase_30 AC 1,039 ms
47,340 KB
testcase_31 AC 897 ms
41,348 KB
testcase_32 AC 1,113 ms
51,340 KB
testcase_33 AC 1,419 ms
60,248 KB
testcase_34 AC 1,401 ms
59,776 KB
testcase_35 AC 1,444 ms
61,684 KB
testcase_36 AC 1,438 ms
61,428 KB
権限があれば一括ダウンロードができます

ソースコード

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){
	int R = max(n,p); int C = p+m;
	vector<vector<T>> V( R, vector<T>(C, 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(R, -1);

	//foward
	for(int col=0; col<C && row<R; col++){
		//pivot
		T val = abs( V[row][col] );
		int pivot = row;
		for(int j=row+1; j<R; 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<R; 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=R-1; i>=0; i--){
		bool zero = true;
		bool valid = true;
		for(int col=0; col<p; col++) if(V[i][col] != 0) zero = false;
		for(int col = p; zero && col<C; 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<C; j++) V[i][j] = (V[i][j] * inv) % mod;

		for(int j=i-1; j>=0; j--){
			for(int k=0; k<C; 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