Fortress Wall
Time limit10sMemory limit512 MB
Count square one-cell-thick borders of size at least L that fit in an H by W grid without covering a tree.
- Level
Medium7 of 10
- Topics
- Prefix sum, Matrix
- Solved
- No attempts yet
Problem
Professor JOI, a historian, studies the IOI Kingdom that existed long ago.
Earlier surveys say the IOI Kingdom was a grid cells tall and cells wide, and that its capital was ringed by a fortress wall for defense.
The wall around the capital had this shape.
- A wall has a size with .
- A wall of size is an square region with its inner square region removed, so it is a border one cell thick.
Another survey says the size of the wall around the capital was at least . Some cells hold an old tree, and a cell with a tree held no wall. The wall occupies the border only, so a tree strictly inside the border does not block it.
Professor JOI wants to know how many walls are possible given these facts. Two walls of the same size in different positions count as different walls.
Given the size of the kingdom, the minimum size of the wall, and the positions of the trees, write a program that counts the possible walls.
Input
The first line contains the integers , , , separated by spaces. The kingdom is cells tall and cells wide, the minimum size of the wall is , and the number of trees is .
Each of the next lines contains the position of a tree, and , separated by a space. The -th tree stands in row from the top and column from the left.
Output
Print the number of possible walls on the first line.
Constraints
- ()
- ()
- whenever