【C.踩不出足迹】打表能发现规律,无论数组是什么,只会出现两种结果,cur=a_1 ^ a_2 ^...^ a_n和对cur逐位取反。
取一个max就行了。
from math import * n,k = input().split(' ') n = int(n) k = int(k) a = input().split(' ') def f(cur): res = 0 for i in range(k): if (cur & (1<<i)) == 0: res = res | (1<<i) return res for i in range(n): a[i] = int(a[i]) if n == 1: print(a[0]) else: cur = a[0] for i in range(1, n): cur ^= a[i] print(max(cur, f(cur)))