B - Who is missing? Editorial by nok0


ビットごとの排他的論理和を表す記号を \(\oplus\) とします。

\(a \oplus a = 0\) であることを用います。 入力で与えられた \(A\) 全ての排他的論理和を考えると、上述の性質より \(4\) 枚存在するようなカードについての排他的論理和は \(0\) となり、\(3\) 枚しか存在しないカードの値が残ります。

すなわち、答えは \(A_1 \oplus A_2 \oplus \dots \oplus A_{4N-1}\) と一致します。

実装例 (C++):

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

int main() {
	int n;
	cin >> n;
	vector a(n * 4 - 1, 0);
	for(auto &v : a) cin >> v;
	cout << accumulate(a.begin(), a.end(), 0, [](int x, int y) { return x ^ y; }) << '\n';
	return 0;
}

posted:
last update: