fork download
  1. int minimumCostPath(vector<vector<int>>& grid)
  2. {
  3. int n = grid.size(), m = grid[0].size();
  4.  
  5. vector<vector<int>> cost(n,vector<int>(m,1e9));
  6.  
  7. cost[0][0] = grid[0][0];
  8.  
  9. priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>,
  10. greater<pair<int,pair<int,int>>>> pq;
  11.  
  12. pq.push({cost[0][0],{0,0}});
  13.  
  14. int row[] = {0,-1,0,1};
  15. int col[] = {1,0,-1,0};
  16.  
  17. while(!pq.empty())
  18. {
  19. int cst = pq.top().first;
  20. int i = pq.top().second.first;
  21. int j = pq.top().second.second;
  22. pq.pop();
  23.  
  24. for(int k=0;k<4;k++)
  25. {
  26. int nr = i+row[k];
  27. int nc = j+col[k];
  28.  
  29. if(nr<0 || nc<0 || nr>=n || nc>=m)
  30. continue;
  31.  
  32. if(cost[nr][nc] > cst+grid[nr][nc])
  33. {
  34. cost[nr][nc] = cst+grid[nr][nc];
  35. pq.push({cost[nr][nc],{nr,nc}});
  36. }
  37. }
  38. }
  39.  
  40. return cost[n-1][m-1];
  41. }
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:25: error: ‘vector’ was not declared in this scope
     int minimumCostPath(vector<vector<int>>& grid)
                         ^~~~~~
prog.cpp:1:32: error: ‘vector’ was not declared in this scope
     int minimumCostPath(vector<vector<int>>& grid)
                                ^~~~~~
prog.cpp:1:39: error: expected primary-expression before ‘int’
     int minimumCostPath(vector<vector<int>>& grid)
                                       ^~~
stdout
Standard output is empty