forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(CODEFORCES) Johnny and His Hobbies.cpp
60 lines (49 loc) · 1.15 KB
/
(CODEFORCES) Johnny and His Hobbies.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
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define one(x) __builtin_popcountll(x)
#define pp pair<ll,ll>
#define all(x) (x).begin(), (x).end()
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
typedef long long int ll;
void subMain(){
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
sort(all(a));
for(int i = 1; i <= 1024; i++){
vector<int> b;
for(int j = 0; j < n; j++){
b.push_back(i^a[j]);
}
sort(all(b));
if(a==b){
cout << i << "\n";
return;
}
}
cout << "-1" << "\n";
return;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
ll t, i = 0;
cin >> t;
while(t--){
//cout << "Case #" << i+1 << ": ";
subMain();
//i++;
}
//subMain();
return 0;
}