結果

問題 No.184 たのしい排他的論理和(HARD)
ユーザー Yang33Yang33
提出日時 2018-07-30 13:42:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 2,730 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 168,100 KB
実行使用メモリ 4,808 KB
最終ジャッジ日時 2023-09-17 17:45:13
合計ジャッジ時間 3,879 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 33 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 26 ms
4,380 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 38 ms
4,444 KB
testcase_13 AC 41 ms
4,416 KB
testcase_14 AC 24 ms
4,376 KB
testcase_15 AC 45 ms
4,760 KB
testcase_16 AC 37 ms
4,376 KB
testcase_17 AC 40 ms
4,420 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 15 ms
4,500 KB
testcase_21 AC 46 ms
4,712 KB
testcase_22 AC 46 ms
4,808 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 29 ms
4,376 KB
testcase_29 AC 39 ms
4,380 KB
testcase_30 AC 34 ms
4,380 KB
testcase_31 AC 30 ms
4,380 KB
testcase_32 AC 37 ms
4,392 KB
testcase_33 AC 45 ms
4,660 KB
testcase_34 AC 44 ms
4,708 KB
testcase_35 AC 45 ms
4,564 KB
testcase_36 AC 45 ms
4,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/07/30  Problem: yukicoder 184  / Link: http://yukicoder.me/problems/no/184  ----- */
/* ------問題------

頭脳派おたくのkamipeipaa君は勉強を続けています。kamipeipaa君は復習を欠かしません。今日は以下の問題を解いています。

N個のスイッチを発見した。i番目のスイッチにはAiという整数が書かれている。あなたはi番目のスイッチを押すことで、ある整数Xに対して
X=X⊕Ai
という操作を行うことができる。ただし⊕とはビットXORの記号である(参考)。
一度押したスイッチは二度と使用することはできない。
Xははじめ0である。
あなたが作ることができる整数は何種類あるか。

kamipeipaa君はこの問題の制約を厳しくしても解くことができることに気づいたので解くことにしました。あなたも解いてあげてください。

-----問題ここまで----- */
/* -----解説等-----

xor操作はmod2とも見れる。(ゲームでよくやった。)
行列とみれれば簡単で、独立な行の数を求めれば良い。

----解説ここまで---- */


typedef unsigned long long ull;
vector<ull> getrank(vector<ull> v, int B) {// B:= digit
	int n = v.size();
	vector<ull> t(B, 0);
	int used = 0;
	for (int j = B - 1; j >= 0; j--) {
		int i = used;
		while (i < n && (~v[i] >> j & 1)) i++;
		if (i < n) {
			ull x = v[i];
			swap(v[i], v[used++]);
			t[j] = x;
			for (i = used; i < n; i++)
				if (v[i] >> j & 1)
					v[i] ^= x;
		}
	}
	return t;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N; cin >> N;
	vector<ull> a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	auto vec = getrank(a, 62);

	int zeros = count(ALL(vec), 0);
	LL ans = 1LL << (SZ(vec) - zeros);
	cout << ans << "\n";

	return 0;
}
0