結果

問題 No.803 Very Limited Xor Subset
ユーザー e869120e869120
提出日時 2019-05-15 22:14:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,921 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 81,404 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-12 15:44:24
合計ジャッジ時間 3,471 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

long long N, M, P, X[309], Y[309], T[309], L[309], R[309], col[309];
vector<pair<int, int>>G[309]; vector<long long>I, J; bool flag = false;

void Gauss(vector<long long> &A) {
	int rank = 0;
	for (int d = 0; d < 60; ++d) {
		int pivot = -1;
		for (int i = rank; i < (int)A.size(); ++i) {
			if (A[i] & (1LL << d)) {
				pivot = i;
				break;
			}
		}
		if (pivot == -1) continue;
		swap(A[rank], A[pivot]);
		for (int j = 0; j < (int)A.size(); ++j) {
			if (j == rank) continue;
			if (!(A[j] & (1LL << d))) continue;
			A[j] ^= A[rank];
		}
		++rank;
	}
}

void dfs(int pos, int dep) {
	if (col[pos] >= 0) {
		if (col[pos] != dep) flag = true;
		return;
	}
	col[pos] = dep; J.push_back(pos);
	for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i].first, dep ^ G[pos][i].second);
}

int main() {
	cin >> N >> M >> P;
	for (int i = 1; i <= N; i++) cin >> X[i];
	for (int i = 0; i <= N; i++) Y[i] = (X[i] ^ X[i + 1]);
	for (int i = 0; i < M; i++) {
		cin >> T[i] >> L[i] >> R[i];
		G[L[i] - 1].push_back(make_pair(R[i], T[i]));
		G[R[i]].push_back(make_pair(L[i] - 1, T[i]));
	}
	for (int i = 0; i <= N; i++) col[i] = -1;
	for (int i = 0; i <= N; i++) {
		if (col[i] >= 0) continue;
		J.clear(); dfs(i, 0);

		long long E1 = 0; for (int j : J) E1 ^= (Y[j] * col[j]);
		P ^= E1;
		if (i != 0) {
			long long E2 = 0; for (int j : J) E2 ^= (Y[j] * (1 - col[j]));
			I.push_back(E2 ^ E1);
		}
	}

	if (flag == true) {
		cout << "0" << endl;
		return 0;
	}

	Gauss(I);
	sort(I.begin(), I.end());
	reverse(I.begin(), I.end());

	long long cx = P;
	for (int i = 0; i < I.size(); i++) {
		long long P1 = cx;
		long long P2 = (cx ^ I[i]);
		cx = min(P1, P2);
	}

	if (cx != 0) cout << "0" << endl;
	else {
		long long ret = 1;
		for (int i = 0; i < I.size(); i++) { if (I[i] == 0) ret *= 2; ret %= 1000000007; }
		cout << ret << endl;
	}
	return 0;
}
0