Bob and cities
Practice
3.4 (7 votes)
Algorithms
Binary search
Breadth first search
Graphs
Implementation
Medium
Problem
68% Success 3694 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Bob is living in a city in which houses are arranged in Nxblock.

The city is denoted by strings having characters such that '.' denotes house while '#' denotes forests.

Bob has to pay a certain amount LCost, RCost, UCost, DCost to move 1 step across left, right, up or down respectively.

Bob lives in a house having co-ordinates (Stx , Sty) (1-Based Indexing).

You are given Q tasks contains an integer X each. In each task, you have to find number of unique houses (including his house) can be travelled using the amount X.

INPUT

First line contains two space separated integers N and M, denoting number of rows and columns respectively.

Next N lines contain a string each containing M characters. (Note :- Top left corner will denote {1,1} )

Next line containd four space separated integers denoting LCost, RCost, UCost, DCost respectively.

Next line contains two space separated integers Stx and Sty, denoting position of Bob's house.

Next line contains an integer Q denoting number of tasks.

Next Q lines contain an integer X each, denoting the amount Bob have.

Output

For each task, output a single integer denoting the number of unique houses (including his house) Bob can visit using the amount X.

Constraint

1 <= N, M <= 1000

1 <= Stx <= N 

1 <= Sty <= M

1 <= LCost, RCost, UCost, DCost <= 109

1 <= Q <= 105

0  <= X <= 1018 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
GraphsAlgorithmsBreadth-first search
Points:30
14 votes
Tags:
AlgorithmsBreadth First SearchGraphsMedium
Points:30
21 votes
Tags:
AlgorithmsBreadth First SearchGraphsProbability