|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||512 MB||2||1||1||100.000%|
Lim Li the Crab is running a mushroom plantation in her backyard. Her mushroom plantation can be modelled as a grid of R rows and C columns, and each grid square of her mushroom plantation can either be empty, contain a mushroom, or contain a sprinkler. For example, her mushroom plantation could look like this:
Figure 1: A mushroom farm with R = 5 and C = 5.
The distance between a sprinkler and a mushroom is defined as the maximum of their separation in the two axes. In other words, if the mushroom is located at row Xm and column Ym while the sprinkler is located at row Xs and column Ys, their distance will be max(|Xs − Xm|, |Ys − Ym|). Sprinklers only have a limited range, so a sprinkler can only water a mushroom if the distance between them is at most D. For example, if D = 1, the areas reachable by the two sprinklers will be:
Figure 2: Diagram showing the range of the sprinklers.
Mushrooms can only grow and be harvested if enough sprinklers are watering it. Specifically, a mushroom will be harvestable if at least K sprinklers are watering it. Count the number of harvestable mushrooms Lim Li can collect in her plantation.
The first line of input will contain four integers: R, the number of rows, C, the number of columns, D, the maximum distance between a sprinkler and a watered mushroom, and K, the minimum number of sprinklers required for a mushroom to be harvestable.
The next R lines of input will contain C characters each, containing a grid representing the mushroom plantation. Each character will represent the contents of a particular grid square, in the following way:
The output should contain one line with one integer, the maximum number of mushrooms Lim Li can harvest.
5 5 1 1 ....M .M... ..S.. .S... ...M.
Since the range of each sprinkler is only 1, meaning sprinklers can only reach adjacent squares, only the mushroom at (2, 2) is watered.
4 4 4 1 .... .M.. ..MM ...S
Since the range of each sprinkler is 4, the lone sprinkler on the plantation can water all the mushrooms.
1 8 5 2 SM..MM.S
Each mushroom requires both sprinklers to be within range, since K = 2. Only two mushrooms satisfy this condition, the second and third mushrooms from the left.
5 5 2 2 ....M .M... ..S.. .S... ...M.
Since the range of each sprinkler is 2, the mushroom at (2, 2) and the mushroom at (5, 4) can be watered by both sprinklers.