-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1102.cpp
More file actions
29 lines (29 loc) · 1.01 KB
/
Copy path1102.cpp
File metadata and controls
29 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public:
int dirs[5] = {-1,0,1,0,-1};
int maximumMinimumPath(vector<vector<int>>& A) {
int m = A.size(), n = A[0].size();
priority_queue<pair<int,pair<int,int>>> pq;
pq.push({A[0][0],{0,0}});
vector<vector<int>> visited(m,vector<int>(n,INT_MIN));
visited[0][0] = A[0][0];
while(!pq.empty()){
auto curr = pq.top();pq.pop();
int x = curr.second.first, y = curr.second.second;
int value = curr.first;
if(x==m-1 && y==n-1)
return value;
for(int i=0; i<4; i++){
int nr = x + dirs[i];
int nc = y + dirs[i+1];
if(nr<0 || nc<0 || nr>=m || nc>=n)
continue;
if(visited[nr][nc]<min(visited[x][y],A[nr][nc])){
visited[nr][nc] = min(visited[x][y],A[nr][nc]);
pq.push({visited[nr][nc],{nr,nc}});
}
}
}
return visited[m-1][n-1];
}
};