XOR Submatrix
Time limit2sMemory limit512 MB
Build the N by M matrix with A[i][j] = V[i] xor U[j] and find the submatrix whose elementwise xor is maximal.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Trie, Prefix sum, Math
- Solved
- No attempts yet
Problem
Using an array V of size N and an array U of size M, we can build an N×M matrix A where Aij = Vi xor Uj.
Write a program that finds the submatrix of A whose elements xor to the largest value.
Input
The first line gives the array sizes N and M. The second line gives V1, V2, ..., VN, and the third line gives U1, U2, ..., UM.
Output
Print the largest value obtained by xorring all elements of a submatrix of A.
Constraints
- 1 ≤ N, M ≤ 1,000
- 0 ≤ Vi, Uj < 229