Under construction

Still being built. Things may change

Safe Squares (Small)

Interview

Time limit5sMemory limit512 MB

Summary
Count all axis-aligned D by D subgrids of an R by C grid that contain no monster cell.
Level

Medium4 of 10

Topics
Dynamic programming, Matrix, Prefix sum, Implementation
Solved
No attempts yet

Problem

Codejamon trainers keep hunting for monsters, but to anyone who is not a trainer those monsters are dangerous. You want to find the safe spots that hold no monster at all.

Treat the world as a grid. Some cells are occupied by monsters. A safe square is a grid aligned block of D×DD \times D cells, with D≥1D \ge 1, that contains no monster. Count how many safe squares of any size the whole world has.

Input

The first line gives the number of test cases, TT. TT test cases follow.

Each test case starts with a line holding three integers RR, CC, and KK. The grid has RR rows and CC columns and contains KK monsters. KK more lines follow. Each of them holds the row RiR_i and the column CiC_i of the cell where the ii-th monster stands. Rows are numbered from top to bottom starting at 0, and columns are numbered from left to right starting at 0.

Output

For each test case, print one line in the form Case #x: y, where xx is the test case number starting at 1 and yy is the total number of safe squares in that test case.

Constraints

  • 1≤T≤201 \le T \le 20
  • 1≤R≤1001 \le R \le 100
  • 1≤C≤1001 \le C \le 100
  • 0≤K≤min⁡(R×C,100)0 \le K \le \min(R \times C, 100)
  • 0≤Ri<R0 \le R_i < R
  • 0≤Ci<C0 \le C_i < C
  • (Ri,Ci)≠(Rj,Cj)(R_i, C_i) \ne (R_j, C_j) for i≠ji \ne j. No two monsters share a cell.

Hint

The grid of the first test case of the example is:

0 0 0
0 0 0
0 1 0

Here 0 is a cell with no monster and 1 is a cell with a monster. It has 10 safe squares: 8 of size 1×11 \times 1 and 2 of size 2×22 \times 2.

The grid of the second test case is:

0 1 0 1 1 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1 0
1 0 0 0 1 0 0 0 0 1 1
0 0 0 0 1 0 0 0 0 0 1

It has 51 safe squares: 32 of size 1×11 \times 1, 13 of size 2×22 \times 2, 5 of size 3×33 \times 3, and 1 of size 4×44 \times 4.

Examples1

  1. Example 1

    Input
    2
    3 3 1
    2 1
    4 11 12
    0 1
    0 3
    0 4
    0 10
    1 0
    1 9
    2 0
    2 4
    2 9
    2 10
    3 4
    3 10
    
    Expected output
    Case #1: 10
    Case #2: 51