Modified Dijkstra's
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int minTimeToReach(vector<vector<int>>& moveTime) {
        priority_queue<pair<int,pair<int,pair<int,int>>>, 
        vector<pair<int, pair<int,pair<int,int>>>>, 
        greater<pair<int,pair<int,pair<int,int>>>>>pq; 
        pq.push({0,{0,{0,0}}}) ; 
        int n = moveTime.size() ; 
        int m = moveTime[0].size()  ; 
        vector<vector<int>>time(n,vector<int>(m,INT_MAX)); 
        time[0][0]=0; 
        int drow[]={1,0,-1,0} ; 
        int dcol[] = {0,-1,0,1} ; 
        while(!pq.empty()){
            int row = pq.top().second.second.first; 
            int col = pq.top().second.second.second; 
            int turn = pq.top().second.first; 
            int t = pq.top().first; 
            pq.pop() ; 
            if(row==n-1 &&col==m-1)return t;  
            for(int i=0; i<4; i++){
                int nrow =row+drow[i]  ; 
                int ncol = col+dcol[i] ; 
                if(nrow<n && nrow>=0 && ncol<m && ncol>=0){
                    if(turn==0){
                        if(moveTime[nrow][ncol]>t){
                            if(time[nrow][ncol]>moveTime[nrow][ncol]+1){
                                time[nrow][ncol]=moveTime[nrow][ncol]+1; 
                                pq.push({moveTime[nrow][ncol]+1, {!turn, {nrow,ncol}}}); 
                            }
                        }
                        else{
                            if(time[nrow][ncol]>t+1){
                                time[nrow][ncol]=t+1; 
                                pq.push({t+1, {!turn, {nrow,ncol}}}) ; 
                            }
                        }
                    }
                    else{
                        if(moveTime[nrow][ncol]>t){
                            if(time[nrow][ncol]>moveTime[nrow][ncol]+2){
                                time[nrow][ncol]=moveTime[nrow][ncol]+2; 
                                pq.push({moveTime[nrow][ncol]+2, {!turn, {nrow,ncol}}}); 
                            }
                        }
                        else{
                            if(time[nrow][ncol]>t+2){
                                time[nrow][ncol]=t+2; 
                                pq.push({t+2, {!turn, {nrow,ncol}}}) ; 
                            }
                        }
                    }
                }
            }
        }
        return time[n-1][m-1] ;
    }
};
```
['C++']