#P16840. [GKS 2021 #A] Checksum
[GKS 2021 #A] Checksum
Problem Description
Grace and Edsger are constructing a boolean matrix . The element in the -th row and -th column is represented by . They decide to note down the checksum (defined as bitwise XOR of given list of elements) along each row and column. Checksum of the -th row is represented as . Checksum of the -th column is represented as .
For example, if , , then and .
Once they finished the matrix, Edsger stores the matrix in his computer. However, due to a virus, some of the elements in matrix are replaced with in Edsger's computer. Luckily, Edsger still remembers the checksum values. He would like to restore the matrix, and reaches out to Grace for help. After some investigation, it will take hours for Grace to recover the original value of from the disk. Given the final matrix , cost matrix , and checksums along each row () and column (), can you help Grace decide on the minimum total number of hours needed in order to restore the original matrix ?
Input Format
The first line of the input gives the number of test cases, . test cases follow.
The first line of each test case contains a single integer .
The next lines each contain integers representing the matrix . The -th element on the -th line represents .
The next lines each contain integers representing the matrix . The -th element on the -th line represents .
The next line contains integers representing the checksum of the rows. The -th element represents .
The next line contains integers representing the checksum of the columns. The -th element represents .
Output Format
For each test case, output one line containing Case #x: y, where is the test case number (starting from ) and is the minimum number of hours to restore matrix .
3
3
1 -1 0
0 1 0
1 1 1
0 1 0
0 0 0
0 0 0
1 1 1
0 0 1
2
-1 -1
-1 -1
1 10
100 1000
1 0
0 1
3
-1 -1 -1
-1 -1 -1
0 0 0
1 1 3
5 1 4
0 0 0
0 0 0
0 0 0
Case #1: 0
Case #2: 1
Case #3: 2
Hint
In Sample Case #, can be restored using the checksum of either -st row or -nd column. Hence, Grace can restore the matrix without spending any time to recover the data.
In Sample Case #, Grace spends hour to recover . After that, she can use checksums of -st row and -st column to restore and respectively. And then she can use checksum of -nd row to restore . Hence, Grace can restore the matrix by spending hour.
In Sample Case #, Grace can spend hour to recover and another hour to recover . After that, she can use checksum to restore the rest of the matrix. Hence, Grace can restore the matrix by spending hours in total.
Limits
.
, for all , .
, for , where , otherwise .
, for all .
, for all .
It is guaranteed that there exist at least one way to replace in with or such that and are satisfied.
Test Set
.
Test Set
.
Test Set
.