Dijkstra's
Intuition\n- No significant change to version I problem. just add move time step to the state variable.\n\n \n# Code\ncpp []\nclass Solution {\npublic:\n    int
# Intuition\n- No significant change to version I problem. just add move time step to the state variable.\n\n \n# Code\n```cpp []\nclass Solution {\npublic:\n    int minTimeToReach(vector<vector<int>>& moveTime) {\n        int rows = moveTime.size(), cols = moveTime[0].size();\n        using State = array<int,4>; // (t, r, c, step) : best time t to reach (r,c) so far, and next move step\n        vector<vector<int>> bsf(rows, vector<int>(cols, INT_MAX)); // best so far\n        priority_queue<State, vector<State>, greater<>> pq;\n        pq.push({0, 0, 0, 1});\n        while(!pq.empty()) {\n            auto [t, r, c, step] = pq.top();\n            pq.pop();\n            if(r + 1 == rows && c+1 == cols)\n                return t;\n            bsf[r][c] = -t; // negate to mark it as done\n            for(auto const& [dr, dc] : vector<array<int,2>>{ {0,1}, {0, -1}, {1, 0}, {-1,0}}) {\n                if(auto R = r+dr, C = c+dc; R >= 0 && R < rows && C >= 0 && C < cols && bsf[R][C] > 0) {\n                    if(auto alt = std::max(t, moveTime[R][C]) + step; alt < bsf[R][C]) {\n                        bsf[R][C] = alt;\n                        pq.push({alt, R, C, 3-step});\n                    }\n                }\n            }\n        }\n        return -1;\n    }\n};\n```
['C++']