XOR Groups
Time limit2sMemory limit512 MB
Erase cells from an N by M grid in increasing value order and after each erasure report the maximum sum of XOR values of the connected groups.
- Level
Medium6 of 10
- Topics
- Union-find, Simulation, Bit manipulation
- Solved
- No attempts yet
Problem
An grid holds one number in every cell, and all of the numbers are different. Among the cells still on the board, cells that touch up, down, left, or right belong to the same XOR group, and the value of a group is the XOR of every number in it. A missing cell in between breaks the link, so one board can hold several XOR groups. The score of the board is the sum of the values of all XOR groups.
Every cell is on the board at the start. You then erase cells one at a time, always the cell holding the smallest number that is left. Each erasure changes the groups and the score. Print the largest score over the starting board before any erasure together with every board that follows an erasure.
Input
The first line has and . ()
Each of the next lines has the numbers of row of the grid, separated by spaces. Every number is an integer between and , and all numbers in the grid are different.
Output
Print the largest score on the first line.