forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMINARRS.cpp
48 lines (41 loc) · 997 Bytes
/
MINARRS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Author : Rajnish Singh
// Codechef : April Lunchtime LTIME71B
#include <bits/stdc++.h>
#define flash \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define pb push_back
#define ll long long int
#define lld long double
#define endl "\n"
using namespace std;
int main() {
flash ll t, n, num, ans;
cin >> t;
while (t-- > 0) {
cin >> n;
ll arr[n];
num = 0;
ans = 0;
for (ll i = 0; i < n; i++) {
cin >> arr[i];
}
for (ll i = 0; i < 30; i++) {
ll coun = 0;
for (int j = 0; j < n; j++) {
if (arr[j] & (1 << i)) {
coun++;
}
}
if (coun > (n / 2)) {
num += 1 << i;
}
}
for (int i = 0; i < n; i++) {
ans += num ^ arr[i];
}
cout << ans << endl;
}
return 0;
}