Saleh127

codeforces 1362Bcpp

Jun 4th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define pi acos(-1)
  6. int main()
  7. {
  8. test
  9. {
  10. int n,a[10000],d,e,f,i,j,k=100000,l;
  11. cin>>n;
  12. for(i=0;i<n;i++)
  13. {
  14. cin>>a[i];
  15. }
  16. sort(a,a+n);
  17. for(i=1;i<=1025;i++)
  18. {
  19. ll c[n];
  20. l=0;
  21. for(j=0;j<n;j++)
  22. {
  23. d=a[j]^i;
  24. c[l]=d;
  25. l++;
  26. }
  27. d=0;
  28. sort(c,c+l);
  29. for(f=0;f<n;f++)
  30. {
  31. if(a[f]!=c[f])
  32. {
  33. d=1;
  34. }
  35. }
  36. if(d==0) break;
  37.  
  38. }
  39. if(d==0) cout<<i<<endl;
  40. else cout<<-1<<endl;
  41. }
  42.  
  43. return 0;
  44. }
Add Comment
Please, Sign In to add comment