結果

問題 No.803 Very Limited Xor Subset
ユーザー leaf_1415leaf_1415
提出日時 2019-03-19 03:54:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 2,493 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 70,976 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-28 11:39:24
合計ジャッジ時間 2,960 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 5 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 7 ms
4,376 KB
testcase_26 AC 6 ms
4,376 KB
testcase_27 AC 6 ms
4,376 KB
testcase_28 AC 6 ms
4,384 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 6 ms
4,376 KB
testcase_31 AC 6 ms
4,376 KB
testcase_32 AC 7 ms
4,380 KB
testcase_33 AC 7 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 4 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define llint long long
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n, m, x;
llint a[305];
vector<P> vec[305];
int mat[405][405];
int h;

void swap(int i, int j)
{
	for(int k = 0; k <= n; k++){
		int t = mat[i][k];
		mat[i][k] = mat[j][k];
		mat[j][k] = t;
	}
}

void GaussianElimination()
{
	int r = 0;
	for(int i = 0; i < n && r < h; i++){
		if(mat[i][r] == 0){
			int max_val = 0, max_j;
			for(int j = r+1; j < h; j++){
				if(mat[j][i] > max_val){
					max_val = mat[j][i];
					max_j = j;
				}
			}
			if(max_val == 0) goto end;
			swap(r, max_j);
		}
		
		for(int j = 0; j < h; j++){
			if(j == r) continue;
			if(mat[j][i] == 0) continue;
			for(int k = 0; k <= n; k++){
				mat[j][k] ^= mat[r][k];
			}
		}
		r++;
		end:;
	}
}

int main(void)
{
	cin >> n >> m >> x;
	for(int i = 0; i < n; i++) cin >> a[i];
	llint t, l, r;
	for(int i = 0; i < m; i++){
		cin >> t >> l >> r;
		l--, r--;
		vec[l].push_back(make_pair(r, t));
	}
	
	for(int i = 0; i < n; i++){
		sort(vec[i].begin(), vec[i].end());
		for(int j = 0; j < vec[i].size(); j++){
			if(vec[i][j].first == vec[i][0].first){
				if(vec[i][j].second != vec[i][0].second){
					cout << 0 << endl;
					return 0;
				}
			}
			else{
				vec[vec[i][0].first+1].push_back(make_pair(vec[i][j].first, vec[i][0].second^vec[i][j].second));
			}
		}
	}
	
	for(int i = 0; i < 30; i++){
		for(int j = 0; j < n; j++){
			if(a[j] & (1<<i)) mat[i][j] = 1;
			else mat[i][j] = 0;
		}
		if(x & (1<<i)) mat[i][n] = 1;
		else mat[i][n] = 0;
	}
	h = 30;
	for(int i = 0; i < n; i++){
		if(vec[i].size() == 0) continue;
		//cout << i << " " << vec[i][0].first << " " << vec[i][0].second << endl;
		for(int j = 0; j < n; j++){
			if(j >= i && j <= vec[i][0].first) mat[h][j] = 1;
			else mat[h][j] = 0;
		}
		mat[h][n] = vec[i][0].second;
		h++;
	}
	
	/*for(int i = 0; i < h; i++){
		for(int j = 0; j <= n; j++){
			cout << mat[i][j] << " ";
		}
		cout << endl;
	}*/
	
	GaussianElimination();
	
	/*cout << endl;
	for(int i = 0; i < h; i++){
		for(int j = 0; j <= n; j++){
			cout << mat[i][j] << " ";
		}
		cout << endl;
	}*/
	
	llint rank = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < n; j++){
			if(mat[i][j]){
				rank++;
				goto pass;
			}
		}
		if(mat[i][n]){
			cout << 0 << endl;
			return 0;
		}
		pass:;
	}
	
	llint ans = 1;
	for(int i = 0; i < n-rank; i++) ans *= 2, ans %= mod;
	cout << ans << endl;
	
	return 0;
}
0