42. Lawn of Threepeaters

Time Limit: 2 seconds

Memory Limit: 1024 MB

Rating: 1200

Problem Statement

Note: rows are referred to as lanes in this question Note: 1-indexing will be used in the explanation of this question, which means the first lane is referred to as lane $1$, and the last lane is referred to as lane $n$ Threepeater is a plant in Plant vs Zombies which shoots one pea in three lanes. More formally, if a threepeater is planted at lane $x$, it will shoot a pea in lane $x - 1$, lane $x$, and lane $x + 1$. If a threepeater is planted at lane $1$, it will shoot a pea in lane $1$ and lane $2$, but not lane $0$ because lane $0$ does not exist. Similarly, if a threepeater is planted at lane $n$, it will not shoot a pea in lane $n + 1$ as the lane does not exist. You are given an integer $n$, representing the dimensions of the lawn. The lawn will be of $n * n$ size. You are then given a 2D grid, representing the lawn. A character ‘p’ represents a peashooter, whereas a character ‘.’ represents nothing. You are given an array $h$, representing the health of the zombies. There will be one zombie on each lane (lane) with health $h_i$ which needs $h_i$ peas to kill. In other words, the first integer in the array is the health of the zombie on the first lane etc. Determine the number of zombies which will be killed.

Input

You are given an integer $n$, representing the dimensions of the lawn. The lawn will be of $n * n$ size. You are then given a 2D grid, representing the lawn. A character ‘p’ represents a peashooter, whereas a character ‘.’ represents nothing. You are given an array $h$, representing the health of the zombies.

Output

Output the answer described in the Problem Statement.

Sample Cases
Sample Input 1:
3
…
p..
…
1 2 1

Sample Output 1:
2


Sample Input 2:
3
..p
…
…
1 2 1

Sample Output 2:
1


Sample Input 3:
5
.p..p
ppp..
..p.p
.....
pp.p.
6 2 5 8 3

Sample Output 3:
3
Explanation

Not available for this problem.

Sources

KL Coding Cup March 2023 > Plants vs Zombies > Problem 3

Submit | Back