Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. Yi Kai has overslept and realized that he has very little time left to attend a very important event! Having recently moved, he takes out a map to navigate through his new neighbourhood to reach his destination. The map shows that the neighbourhood is arranged in a grid of size ~n~ by ~m~, with a ~o~ indicating a walkable path which takes 1 minute to walk across, and an ~X~ indicating a building. He takes out his marker, looks around his surroundings, and marks his current position with an ~s~ on the map. Then, he finds his destination, and marks an ~e~ on it. He looks at the map again, but the number of possible routes to his destination overwhelms him! Help Yi Kai find out how much time he will need to reach his destination if he uses the shortest possible route!
  2.  
  3. (Inspired by Yi Kai oversleeping before previous NOI trainings)
  4.  
  5. ## Input ##
  6.  
  7. The first line will contain two integers, ~n~, and ~m~.
  8. The next n lines will contain m characters each, one of ~.~, ~X~, ~s~ or ~e~.
  9.  
  10. Output
  11. ------
  12.  
  13. A single integer, the minimum time he requires to reach his destination in minutes, or ~-1~ if it is not possible and he has to call for a helicopter.
  14.  
  15. **Limits**
  16. ----------
  17. ~1 < n,m <= 1000~
  18.  
  19. **Sample Testcase 1**
  20. ---------------------
  21.  
  22. **Input**
  23.  
  24. 4 4
  25. s...
  26. ....
  27. ....
  28. ...e
  29.  
  30. **Output**
  31.  
  32. 5
  33.  
  34. **Sample Testcase 2**
  35. ---------------------
  36.  
  37. **Input**
  38.  
  39. 3 4
  40. XXXe
  41. ....
  42. sXXX
  43.  
  44. **Output**
  45.  
  46. 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement