CPP | BFS - shortest path + greedy
Code

# Code
```cpp []
class Solution {
public:
    #define vt vector<int>
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    bool valid(int i,int j, int m,int n)
    {
        if(i>=0 && j>=0 && i<m && j<n)
           return true;
        return false;   
    }
    bool possible(int i,int j, int t, vector<vector<int>>& grid)
    {
        int m=grid.size(), n=grid[0].size();
        for(int k=0;k<4;k++)
        {
            int x=i+dx[k],y=j+dy[k];
            if(valid(x,y,m,n) && grid[x][y]<=t+1)
                return true;
        }
        return false;
    }
    int minimumTime(vector<vector<int>>& grid) 
    {
        int m=grid.size(), n=grid[0].size();
        priority_queue<vt,vector<vt>,greater<vt>>pq;
        pq.push({0,0,0});
        vector<vector<bool>>vis(m,vector<bool>(n,false));
        vis[0][0]=true;
        while(!pq.empty())
        {
            int t=pq.top()[0],i=pq.top()[1],j=pq.top()[2];
            pq.pop();
            if(i==m-1 && j==n-1)
               return t;
            for(int k=0;k<4;k++)
            {
                int x=i+dx[k],y=j+dy[k];
                if(valid(x,y,m,n) && !vis[x][y])
                {
                    if(grid[x][y]<=t+1)
                    {
                        pq.push({t+1,x,y});
                        vis[x][y]=true;
                    }    
                    else if(possible(i,j,t,grid))
                    {
                        int diff=(grid[x][y]-t);
                        int td=diff+((diff+1)%2);
                        pq.push({t+td,x,y});
                        vis[x][y]=true;
                    }    
                }
            }   
        }
        return -1;
    }
};
```
['C++']