Back to General discussions forum
One day, Tom decided to eat, "How good it is that i have lots of sausages left"- he though while opening the fridge but he was unlucky. Exacly before T seconds his cat stole all D sausages. Help him to save them
Imagine Tom's house as a rectangle with N rows and M collums cells are marked like that:
'S' - fridge
'#' - wall
'.' - empty cell
'P' - cupboard
the house is also surounded by walls. Tom and his cat can move in 4 directions (N,E,S,W) throught all cell except walls.
Cat always runs with specific moving pattern: First he runs West, if he hits a wall he will keep turning left till he can run straight if he goes to a cell with cupboard he hides inside and stars eating sausages 1 per second
Tom knows all that so he goes straight to cupboard the cat is running to.
Moving between cells takes 1 second changing directions doesn't take any time.
Find the maximum amount of sausages Tom can save
Input: D,T,N,M and array of Tom's house
Extra info: There is always one fridge in the house
Example: