Concise and easiy to follow solution using dp and heap
Intuition\nInspired by many solutions from question: Find Minimum Time to Reach Last Room I\n\n# Approach\nUsing minheap to follow the path that has minimum tim
# Intuition\nInspired by many solutions from question: [Find Minimum Time to Reach Last Room I](https://leetcode.com/problems/find-minimum-time-to-reach-last-room-i/description/)\n\n# Approach\nUsing minheap to follow the path that has minimum time\nUsing dp to store the minimum time to get to a specific node(dungeon)\nif we reach the end of the matrix, we immidiately return the result\n\n\n# Code\n```python3 []\nclass Solution:\n    def minTimeToReach(self, moveTime: List[List[int]]) -> int:\n        #i set the first node to be -1 because we start with 0 time, and later in the code i will add 1 so it becomes 0\n        moveTime[0][0] = -1\n        #our min heap, (curTime,x,y,curStep)\n        queue = [(-1,0,0,0)]\n        lenN = len(moveTime)\n        lenM = len(moveTime[0])\n        dp = [[float(\'inf\')]*lenM for _ in range(lenN)]\n\n        while queue:\n            curTime, x, y,curStep = heappop(queue)\n\n            #only continue if we are in the matrix\n            if 0<=x<lenN and 0<=y<lenM:\n                \n                curTime = max(curTime, moveTime[x][y])+ curStep\n\n                #switch step\n                if curStep == 1:\n                    curStep = 2\n                else:\n                    curStep = 1\n\n                if (x,y) == (lenN-1,lenM-1):\n                    return curTime\n\n                #if we meet a better way, we update the dp and add its adjacent nodes to the queue\n                if curTime<dp[x][y]:\n                    dp[x][y] = curTime\n                    heappush(queue,(curTime,x+1,y,curStep))\n                    heappush(queue,(curTime,x-1,y,curStep))\n                    heappush(queue,(curTime,x,y+1,curStep))\n                    heappush(queue,(curTime,x,y-1,curStep))\n\n```
['Python3']