## BSSPC '21 S4 - Child Prodigy Chadstin

View as PDF

Points: 17 (partial)
Time limit: 5.0s
Memory limit: 256M

Author:
Problem types

Austin the smurfing smurf orzianna main has an binary matrix he wants to compress.

A single compression consists of splitting the matrix into adjacent non overlapping blocks and constructing a new matrix in which each bit is representative of a single block in the original matrix, given that all bits were of the same value. The value of a bit in the new matrix is the same as that of the bits in the block it represents. The adjacency of bits in the new matrix reflects that of the blocks in the original matrix. The entire matrix can only be compressed if each block only contains bits of the same value.

For example, the following matrices are compressible:

While these are not:

Finally, some can be compressed multiple times:

Austin knows the top left and bottom right row and column numbers of possibly overlapping rectangles within the matrix. He knows that all bits within these rectangles are of value , while all bits that aren't in any of the specified rectangles are of value . Given these rectangles, can you help him find out how many times he can compress his matrix?

#### Input Specification

The first line contains three integers , , and , which represent the number of rows in the matrix, the number of columns in the matrix, and the number of rectangles in the matrix, respectively.

The next lines each contain four integers , , , and - the row and column numbers of the top left and bottom right corners of the rectangle.

#### Output Specification

Output a single integer, the number of times the compression algorithm can be applied to the given matrix.

#### Sample Input 1

4 4 2
1 1 2 2
3 3 4 4

#### Sample Output 1

1

#### Sample Input 2

6 6 4
1 2 2 6
2 1 6 2
1 1 1 1
5 5 6 6

#### Sample Output 2

1

#### Sample Input 3

2 4 1
1 1 2 2

#### Sample Output 3

1

#### Sample Input 4

2 2 3
1 1 1 1
1 2 1 2
2 2 2 2

#### Sample Output 4

0

#### Sample Input 5

9 9 4
4 1 6 3
1 4 3 6
4 7 6 9
7 4 9 6

#### Sample Output 5

0

#### Sample Input 6

4 4 2
1 1 3 4
4 1 4 4

#### Sample Output 6

2