#ABC4074. Domino Covering XOR
Domino Covering XOR
Time Limit: 2 sec / Memory Limit: 1024 MB
Problem Statement
There is a grid with rows and columns. Let denote the cell at the row from the top and the column from the left .
Cell has a non-negative integer written on it.
Let us place zero or more dominoes on the grid. domino covers two adjacent cells, namely one of the following pairs:
1、cells and for ;
2、cells and for .
No cell may be covered by more than one domino.
For a placement of dominoes, define its score as the bitwise of all integers written in cells not covered by any domino.
Find the maximum possible score.
What is bitwise ?
For non-negative integers and , their bitwise is defined as follows:
In binary, the bit of is if exactly one of and has in that bit, and otherwise. For example, (in binary, ). For non-negative integers , their bitwise is , which can be proved to be independent of the order of the operands.
Constraints
All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Output the answer.
Sample Input 1
3 4
1 2 3 8
4 0 7 10
5 2 4 2
Sample Output 1
15
The grid is as follows:
For example, the placement below yields a score of 15.
No placement achieves a score of 16 or higher, so output 15.
Sample Input 2
1 11
1 2 4 8 16 32 64 128 256 512 1024
Sample Output 2
2047
You may also choose to place no dominoes.
Sample Input 3
4 5
74832 16944 58683 32965 97236
52995 43262 51959 40883 58715
13846 24919 65627 11492 63264
29966 98452 75577 40415 77202
Sample Output 3
131067