easy c++ solution
Intuition\nwe will not reach the destination only when grid[0][1]and grid[1][0] both of them are greater than one otherwise we can go to the grid which is reach
# Intuition\nwe will not reach the destination only when grid[0][1]and grid[1][0] both of them are greater than one otherwise we can go to the grid which is reachable and can increse time by oscillating between the places .For even we will see in howmany minimum time it is possible and we will do the same for odd. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumTime(vector<vector<int>>& grid) {\n    int n =grid.size();\n    int m =grid[0].size();\n    vector<pair<int,int>>direc={{0,1},{0,-1},{1,0},{-1,0}};\n    vector<vector<long long>>mov(n,vector<long long>(m,1e10));\n    set<pair<long long,pair<int,int>>>st;\n    mov[0][0]=0;\n    st.insert({0,{0,0}});\n    if(grid[0][1]>1&&grid[1][0]>1){\n        return -1;\n    }\n      while(!st.empty()){\n          auto it =*st.begin();\n          long long  dis =it.first;\n          int row = it.second.first;\n          int col = it.second.second;\n          st.erase(st.begin());\n          if(dis>mov[row][col])continue;\n          for(auto p:direc){\n              int nr =row+p.first;\n              int nc= col+p.second;\n              if(nr>=0&&nr<n&&nc>=0&&nc<m){\n                  long long add=1;\n                  if(dis+1>=grid[nr][nc]){\n                    add=1;\n                  }\n                  else{\n                      if((grid[nr][nc]-dis)%2==0){\n                        add=grid[nr][nc]-dis+1;\n                      }\n                      else{\n                        add=grid[nr][nc]-dis;\n                      }\n                  }\n                  if(mov[row][col]+add<mov[nr][nc]){\n                      mov[nr][nc]=dis+add;\n                      st.insert({mov[nr][nc],{nr,nc}});\n                  }\n                  \n              }\n          }\n      }\n    return mov[n-1][m-1];\n    \n     \n    }\n};\n```
['C++']