Bitwise Subset XOR Sum
Python
Hard
3 views
Problem Description
Read n numbers, consider all subsets. For each subset take XOR of its elements. Output the sum of XOR over all subsets.
Input Format
First line n. Second line n integers.
Output Format
One integer sum.
Official Solution
import sys
p=sys.stdin.read().strip().split()
if not p: sys.exit(0)
n=int(p[0])
a=list(map(int,p[1:1+n]))
orv=0
for x in a:
orv |= x
ans=orv * (1<<(n-1))
sys.stdout.write(str(ans))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!