Safe Squares (Large)
Time limit5sMemory limit512 MB
Count all grid-aligned square regions of any size that contain no monster, given a sparse set of at most K monster cells on an R by C board.
- Level
Hard8 of 10
- Topics
- Array, Dynamic programming, Prefix sum, Matrix
- Solved
- No attempts yet
Problem
Monster trainers go looking for monsters, but a monster is dangerous to anyone who is not a trainer. You want to find safe spots that hold no monsters.
Think of the world as a grid. Some cells hold one monster each. A safe square is a grid-aligned square region of cells that contains no monster at all (). Count how many safe squares of any size the whole world has. Two squares of the same size at different positions count separately.
Input
The first line contains the number of test cases .
Each test case starts with a line holding three integers , , and . The grid has rows and columns and holds monsters. Each of the next lines holds the row and the column of the -th monster. Rows are numbered from top to bottom starting at 0, and columns from left to right starting at 0.
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting at 1 and is the number of safe squares in that test case.
Constraints
- ()
- ()
- for . No cell holds more than one monster.