Queries on 2D array

Revision en2, by damu, 2018-10-11 09:28:52

Bob is living in a city in which houses are arranged in N*M blocks The city is denoted by N strings having M characters such that '.' denotes house while '#' denotes forests. Bob has to pay a certain amount LCost, RCost, UCost, DCost to move 1 step accross left, right, up or down respectively. Bob lives in a house having coordinates (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.

Constraints 1<=N,M<=1000 1<=LCost,RCost,UCost,DCost<=10^9 1<=Q<=10^5 0<=X<=10^18 Time limit 1 second

Sample input 3 4 (N, M)

..#.

...

..#.

1 2 3 4 (LCost, RCost,UCost, DCost) 2 3 (Stx, Sty) 3 (Q) 3 2 5 10

Output 3 7 9 Could anyone give hint on how to solve this problem?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English damu 2018-10-11 09:36:23 18
en3 English damu 2018-10-11 09:33:16 31 Tiny change: '4 (N, M)\n ..#.\n ' -> '4 (N, M)\n\n ..#.\n '
en2 English damu 2018-10-11 09:28:52 4 Tiny change: '4 (N, M)\n..#.\n#...\n..#.\n1 2 3 4 ' -> '4 (N, M)\n\n..#.\n#...\n..#.\n\n1 2 3 4 '
en1 English damu 2018-10-11 09:23:23 852 Initial revision (published)