Loading...
Submission
# When Author Problem Language CPU Memory
20815 2024-06-08 22:51:20 AHAMMED_99 Find MinMaxXoR Number C 0 ms 1552 kb Wrong Answer - 3
Test Cases
# CPU Memory Points
1 0 ms 1552 kb 1 Accepted
2 0 ms 1552 kb 1 Accepted
3 0 ms 1536 kb 0 Wrong Answer
4 0 ms 0 kb 0 Skipped
5 0 ms 0 kb 0 Skipped
6 0 ms 0 kb 0 Skipped
7 0 ms 0 kb 0 Skipped
8 0 ms 0 kb 0 Skipped
9 0 ms 0 kb 0 Skipped
10 0 ms 0 kb 0 Skipped
11 0 ms 0 kb 0 Skipped
12 0 ms 0 kb 0 Skipped
13 0 ms 0 kb 0 Skipped
14 0 ms 0 kb 0 Skipped
15 0 ms 0 kb 0 Skipped
16 0 ms 0 kb 0 Skipped
Source Code
  1. #include <stdio.h>
  2.  
  3. int min(int a, int b) {
  4. return a < b ? a : b;
  5. }
  6.  
  7. int max(int a, int b) {
  8. return a > b ? a : b;
  9. }
  10.  
  11. int calculate_min_max_xor(int arr[], int n) {
  12. int min_max_xor = 0;
  13.  
  14. // Count the number of occurrences of each bit
  15. for (int bit = 30; bit >= 0; bit--) {
  16. int count = 0;
  17. for (int i = 0; i < n; i++) {
  18. if (arr[i] & (1 << bit))
  19. count++;
  20. }
  21.  
  22. // For each bit position, if count is odd, then set the bit in the answer
  23. if (count % 2 == 1)
  24. min_max_xor |= (1 << bit);
  25. }
  26.  
  27. return min_max_xor;
  28. }
  29.  
  30. int main() {
  31. int n;
  32. scanf("%d", &n);
  33.  
  34. int arr[n];
  35. for (int i = 0; i < n; i++) {
  36. scanf("%d", &arr[i]);
  37. }
  38.  
  39. int min_max_xor = calculate_min_max_xor(arr, n);
  40. printf("%d\n", min_max_xor);
  41.  
  42. return 0;
  43. }
  44.