Largest Block |
Consider a n x n chessboard. The term block(r1,c1,r2,c2) denotes the rectangular subset of squares defined by the intersection of rows {r1,r1+1,...,r2} and columns {c1,c1+1,...,c2}.
There are several occupied blocks on the board. We are interested in the largest block (in the sense of maximum area) that can be placed in the free space remaining in the board.
For example, in a chessboard of size 10, if block(2,2,5,3), block(8,3,9,7), and block(3,6,3,8) represent occupied space, then the largest block that can be placed in free space has area 28. This can be visually checked in the following figure:
r\c | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
---|---|---|---|---|---|---|---|---|---|---|
1 |
||||||||||
2 |
X | X | ||||||||
3 |
X | X | X | X | X | |||||
4 |
X | X | o | o | o | o | o | o | o | |
5 |
X | X | o | o | o | o | o | o | o | |
6 |
o | o | o | o | o | o | o | |||
7 |
o | o | o | o | o | o | o | |||
8 |
X | X | X | X | X | |||||
9 |
X | X | X | X | X | |||||
10 |
We are interested only in the area of the largest free block, and not in its particular location. Therefore, each instance of the problem has a unique solution.
The program first reads the number p of instances of the problem. Each instance is described by the size s of the board, the number b of blocks of occupied space, and the vertices r1,c1,r2,c2, of each block:
p | number of problem instances in the file | |
s | (board size) | instance #1 |
n | (number of blocks) | |
r1 c1 r2 c2 | (first block) | |
r1 c1 r2 c2 | (second block) | |
... | ... | |
r1 c1 r2 c2 | (n-th block) | |
s | (board size) | instance #2 |
n | (number of blocks) | |
r1 c1 r2 c2 | (first block) | |
r1 c1 r2 c2 | (second block) | |
... | ... | |
r1 c1 r2 c2 | (n-th block) | |
... | ... | instance #p |
Assumptions:
For each test case the output consists of a integer indicating the area of the largest block that can be located in the available free squares.
3 10 3 2 2 5 3 8 3 9 7 3 6 3 8 20 1 1 1 1 1 10 2 5 1 5 10 1 5 10 5
28 380 25