fork download
  1. #include <iostream>
  2. #include<vector>
  3. #include<utility>
  4. #include<map>
  5. #include<cmath>
  6. using namespace std;
  7. #define ll long long
  8. int main()
  9. {
  10. ll t;
  11. cin >> t;
  12. while(t--){
  13. vector<ll> setBitCount(30,0);
  14. vector<ll> arr;
  15. ll n;
  16. cin >> n;
  17. for(ll i=0;i<n;++i){
  18. ll temp;
  19. cin >> temp;
  20. arr.emplace_back(temp);
  21. ll k=0;
  22. while(temp!=0){
  23. if(temp&1==1) setBitCount[k]++;
  24. temp=temp>>1;
  25. k++;
  26. }
  27. }
  28. ll x = 0;
  29. ll limit=0;
  30. for(ll i=29;i>=0;i--){
  31. if(setBitCount[i]>0){
  32. limit = i;
  33. break;
  34. }
  35. }
  36. for(ll i=0;i<=limit;++i){
  37. if(setBitCount[i]>n/2) x = x + pow(2,i);
  38. }
  39. ll minSum =0;
  40. for(ll i=0;i<n;++i){
  41. minSum = minSum + arr[i]^x;
  42. }
  43. cout << minSum << endl;
  44. }
  45.  
  46. return 0;
  47. }
  48.  
Runtime error #stdin #stdout #stderr 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
*** Error in `./prog': munmap_chunk(): invalid pointer: 0x0000557c8ad71d30 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bcb)[0x2affe7affbcb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76f96)[0x2affe7b05f96]
./prog(+0x1090)[0x557c89a21090]
./prog(+0xe1a)[0x557c89a20e1a]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x2affe7aaf2b1]
./prog(+0xeea)[0x557c89a20eea]
======= Memory map: ========
2affe6daf000-2affe6dd2000 r-xp 00000000 fd:00 2710543                    /lib/x86_64-linux-gnu/ld-2.24.so
2affe6dd2000-2affe6dd6000 rw-p 00000000 00:00 0 
2affe6ddf000-2affe6de4000 rw-p 00000000 00:00 0 
2affe6fd2000-2affe6fd3000 r--p 00023000 fd:00 2710543                    /lib/x86_64-linux-gnu/ld-2.24.so
2affe6fd3000-2affe6fd4000 rw-p 00024000 fd:00 2710543                    /lib/x86_64-linux-gnu/ld-2.24.so
2affe6fd4000-2affe6fd5000 rw-p 00000000 00:00 0 
2affe6fd5000-2affe7147000 r-xp 00000000 fd:00 2712611                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
2affe7147000-2affe7347000 ---p 00172000 fd:00 2712611                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
2affe7347000-2affe7351000 r--p 00172000 fd:00 2712611                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
2affe7351000-2affe7353000 rw-p 0017c000 fd:00 2712611                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
2affe7353000-2affe7357000 rw-p 00000000 00:00 0 
2affe7357000-2affe745a000 r-xp 00000000 fd:00 2710572                    /lib/x86_64-linux-gnu/libm-2.24.so
2affe745a000-2affe7659000 ---p 00103000 fd:00 2710572                    /lib/x86_64-linux-gnu/libm-2.24.so
2affe7659000-2affe765a000 r--p 00102000 fd:00 2710572                    /lib/x86_64-linux-gnu/libm-2.24.so
2affe765a000-2affe765b000 rw-p 00103000 fd:00 2710572                    /lib/x86_64-linux-gnu/libm-2.24.so
2affe765b000-2affe7671000 r-xp 00000000 fd:00 2710510                    /lib/x86_64-linux-gnu/libgcc_s.so.1
2affe7671000-2affe7870000 ---p 00016000 fd:00 2710510                    /lib/x86_64-linux-gnu/libgcc_s.so.1
2affe7870000-2affe7871000 r--p 00015000 fd:00 2710510                    /lib/x86_64-linux-gnu/libgcc_s.so.1
2affe7871000-2affe7872000 rw-p 00016000 fd:00 2710510                    /lib/x86_64-linux-gnu/libgcc_s.so.1
2affe7872000-2affe788a000 r-xp 00000000 fd:00 2710529                    /lib/x86_64-linux-gnu/libpthread-2.24.so
2affe788a000-2affe7a89000 ---p 00018000 fd:00 2710529                    /lib/x86_64-linux-gnu/libpthread-2.24.so
2affe7a89000-2affe7a8a000 r--p 00017000 fd:00 2710529                    /lib/x86_64-linux-gnu/libpthread-2.24.so
2affe7a8a000-2affe7a8b000 rw-p 00018000 fd:00 2710529                    /lib/x86_64-linux-gnu/libpthread-2.24.so
2affe7a8b000-2affe7a8f000 rw-p 00000000 00:00 0 
2affe7a8f000-2affe7c24000 r-xp 00000000 fd:00 2710666                    /lib/x86_64-linux-gnu/libc-2.24.so
2affe7c24000-2affe7e23000 ---p 00195000 fd:00 2710666                    /lib/x86_64-linux-gnu/libc-2.24.so
2affe7e23000-2affe7e27000 r--p 00194000 fd:00 2710666                    /lib/x86_64-linux-gnu/libc-2.24.so
2affe7e27000-2affe7e29000 rw-p 00198000 fd:00 2710666                    /lib/x86_64-linux-gnu/libc-2.24.so
2affe7e29000-2affe7e2d000 rw-p 00000000 00:00 0 
557c89a20000-557c89a22000 r-xp 00000000 fd:00 18708487                   /home/bzcNgD/prog
557c89c21000-557c89c22000 r--p 00001000 fd:00 18708487                   /home/bzcNgD/prog
557c89c22000-557c89c23000 rw-p 00002000 fd:00 18708487                   /home/bzcNgD/prog
557c8ad5f000-557c8ad91000 rw-p 00000000 00:00 0                          [heap]
7fff2494d000-7fff2496e000 rw-p 00000000 00:00 0                          [stack]
7fff249db000-7fff249dd000 r-xp 00000000 00:00 0                          [vdso]
7fff249dd000-7fff249df000 r--p 00000000 00:00 0                          [vvar]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]