Trap of Techies

0

0 votes
Problem

Goblin Techies are a ranged Intelligence hero, known for laying deadly traps around the field with a wide array of mines.
Having little direct combat ability, the Techies have an unorthodox, if effective, method of dealing damage to the enemy team in the form of powerful laid explosive mines and stasis traps that enable other heroes to set up a gank or retreat. Their mines, set across key points of the map -and even less conventional locations- are an effective method of denying area and guaranteeing damage if enemies dare to initiate.

Phantom Assassin is chasing Goblin Techies but techies is very smart, so he plants explosives in his routes.
Whole area is made up of N x N grid of cells.
Cells of Grid are numbered from (1,1)......(N,N).
At every point Phantom can move either to the Right or Down.
Techies have two kinds of explosives: Land Mines (denoted by '') and *Remote Mines (denoted by '#').
Land Mines explodes if anyone steps on a cell where the Land Mine is planted. So if Phantom steps on a cell where Land Mine is planted, the mine will explode causing a decrement in her health
D1. Remote Mines can cause damage to all the cells which are in 'zone**' of that Remote Mine.
Zone of any Remote Mine is defined as all the cells which are directly connected (vertically or horizontally or diagonally) to cell where Remote Mine is present.

If Phantom steps on the cell which is in the zone of any Remote Mine, then the Remote Mine will explode. If there are more Remote Mines whose zone lie on the cell Phantom just stepped on, then those mines will also explode. Every exploded remote mine will cause a decrement in her health by D2 separately.

Once any Mine is exploded then it is then empty land (denoted by '.').

You have to tell whether Phantom can reach on grid where Techies is standing. If its possible then print "YES" and find the final health of Phantom if her Initial Health - H is given. If its not possible then print "NO" (Quotes only for clarity).

You have to consider that path only where damage to her health is least.
Assume initially PHANTOM is not in ZONE of any remote mine.

Input:
First line will contain H, D1, D2 i.e. Health of Phantom Assassin , Damage caused by single Land Mine , Damage caused by single Remote Mine respectively.
Next Line will contain N
Next N Lines will contain N characters which will be either (*)->Land Mines,(#)->Remote Mines, (.)->Empty Space but in cell (1,1) there will be character P Initial location of Phantom Assassin and in cell (N,N) there will be character G, location of Techies.

Output:
Output should be either "YES" or "NO". If "YES" then after a space there should be H' (Final Health of Phantom)
If "NO" then print only "NO"

Constraint:
2 ≤ N ≤ 1000
1 ≤ H ≤ 108
1 ≤ D1,D2 ≤ 100000

Test#1
Sample Input

13 8 1  
5  
P**..  
.**.*  
.*...  
*.#..
.*#.G

Sample Output

YES 4

Test#2
Sample Input

18 7 8
5
P*...
.**.*
.*...
.....
***.G

Sample Output

YES 18

Test#3
Sample Input

10 4 3
4
P*#*
..**
#*#*
#.*G

Sample Output

NO

No Partial Marking for this question

Problem Setter: Gurvinder Singh

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?