結果

問題 No.803 Very Limited Xor Subset
ユーザー e869120e869120
提出日時 2019-05-15 22:17:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,844 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 15:48:16
合計ジャッジ時間 3,200 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 0 ms
4,368 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1 ms
4,368 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 2 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 2 ms
4,372 KB
testcase_23 AC 2 ms
4,372 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 2 ms
4,372 KB
testcase_27 AC 2 ms
4,372 KB
testcase_28 AC 2 ms
4,368 KB
testcase_29 AC 2 ms
4,368 KB
testcase_30 AC 2 ms
4,372 KB
testcase_31 AC 2 ms
4,368 KB
testcase_32 AC 1 ms
4,372 KB
testcase_33 AC 2 ms
4,372 KB
testcase_34 AC 2 ms
4,372 KB
testcase_35 AC 2 ms
4,368 KB
testcase_36 AC 2 ms
4,372 KB
testcase_37 AC 2 ms
4,368 KB
testcase_38 AC 2 ms
4,368 KB
testcase_39 AC 2 ms
4,372 KB
testcase_40 AC 2 ms
4,368 KB
testcase_41 AC 2 ms
4,372 KB
testcase_42 AC 2 ms
4,372 KB
testcase_43 AC 2 ms
4,372 KB
testcase_44 AC 2 ms
4,368 KB
testcase_45 AC 2 ms
4,372 KB
testcase_46 AC 2 ms
4,372 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;

vector<long long> Gauss(vector<long long>X) {
	sort(X.begin(), X.end());
	for (int i = 59; i >= 0; i--) {
		for (int j = 0; j < X.size(); j++) {
			if ((X[j] & (1LL << i)) != 0) {
				for (int k = j + 1; k < X.size(); k++) { if ((X[k] & (1LL << i)) != 0) X[k] ^= X[j]; }
				break;
			}
		}
		sort(X.begin(), X.end());
	}
	return X;
}

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;
	}

	I = 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