Zombie Apocalypse
Time limit2sMemory limit512 MB
Given up to 2000 zombie cells on an N by M grid with Chebyshev distance spreading, count how many cells end up at level Q.
- Level
Hard8 of 10
- Topics
- Geometry, Sorting, Implementation, Math
- Solved
- No attempts yet
Problem
Your country has zombies, and that is the problem. You work at the Forensic Institute for Zoology and Zombie Emerging Studies (FIZZES), and your job is to report how bad the situation is.
The country is mapped onto an grid of cells, and every cell gets one non-negative integer. You know the exact location of every zombie, and no two zombies share a cell. The numbers are written in this order.
- Every cell holding a zombie is marked .
- Every unmarked cell touching a cell marked is marked .
- Every unmarked cell touching a cell marked is marked .
- This repeats until every cell carries a number.
Two cells touch when they share a side or a corner, so one cell touches up to eight cells. The number in a cell is the level of concern the institute has about zombie spread at that spot.
For , with zombies in row 2 column 4 and row 3 column 3, the numbers come out like this.
2 2 1 1 1 2
2 1 1 0 1 2
2 1 0 1 1 2
2 1 1 1 2 2
2 2 2 2 2 3
Your boss gives you an integer . Determine how many cells are marked with .
Input
The first line contains two space-separated integers and (, ), the number of rows and the number of columns of the grid.
The second line contains (), the number of zombies.
Each of the next lines contains two space-separated integers and (, ), the row and the column of the -th zombie. No two zombies share a cell, so whenever .
The last line contains the integer ().
Output
Print the number of cells in the grid that are marked with .