 # XORORED-Help needed

After seeing the editorial i think i had the correct idea but my approach wasn’t right still i wanted to know why my code didn’t work
https://www.codechef.com/viewsolution/49166379

you have to print both X and (a1^X) | (a2^X) | …| (an^X).
your code is just printing X.

2 Likes

The best way to solve this question is to first sort the list and take the middle value of the list as X and do the next process given in the question( xor and or).
for odd length of list there is only one middle element.
but for even length there is two middle elements. check it for both the elements. the element which gives the minimum anwser is the x.

1 Like

for i in range(int(input())):
a=int(input())
b=list(map(int,input().split()))
b.sort()
if len(b)%2==0:
c=b[int(len(b)/2)-1]
d=b[int(len(b)/2)]
res=(b ^ c)
res1=(b ^ d)
for j in range(1,len(b)):
res=(res | (b[j] ^ c))
res1=(res1 | (b[j] ^ d))
if min(res,res1)==res1:
print(d,res1)
else:
print(c,res)
else:
c=b[int(len(b)//2)]
res=b^c
for j in range(1,len(b)):
res=(res | (b[j] ^ c))
print(c,res)

XORORED anwser in python. successfully passed in all testcases

1 Like

i feel very stupid now didn’t had to change a thing in my code just printed the val

1 Like