7897 const int m = heights.size();
7898 const int n = heights[0].size();
7899 unordered_set<pair<int, int>, myhash, myeq> pacific;
7900 unordered_set<pair<int, int>, myhash, myeq> atlantic;
7901 queue<pair<int, int>> q;
7902 vector<vector<int>> ans;
7904 for(
int i = 0; i < m; i++) {
7906 pacific.insert({i, 0});
7908 for(
int i = 1; i < n; i++) {
7910 pacific.insert({0, i});
7913 auto [x, y] = q.front();
7915 pair<int, int> nexts[4] = {{x + 1, y}, {x - 1, y}, {x, y + 1}, {x, y - 1}};
7916 for(
auto &[next_x, next_y]: nexts) {
7917 if(next_x >= 0 && next_y >= 0 && next_x < m && next_y < n && heights[next_x][next_y] >= heights[x][y] && !pacific.contains({next_x, next_y})) {
7918 pacific.insert({next_x, next_y});
7919 q.push({next_x, next_y});
7924 for(
int i = 0; i < m; i++) {
7926 atlantic.insert({i, n - 1});
7928 for(
int i = 0; i < n - 1; i++) {
7930 atlantic.insert({m - 1, i});
7933 auto [x, y] = q.front();
7935 pair<int, int> nexts[4] = {{x + 1, y}, {x - 1, y}, {x, y + 1}, {x, y - 1}};
7936 for(
auto &[next_x, next_y]: nexts) {
7937 if(next_x >= 0 && next_y >= 0 && next_x < m && next_y < n && heights[next_x][next_y] >= heights[x][y] && !atlantic.contains({next_x, next_y})) {
7938 atlantic.insert({next_x, next_y});
7939 q.push({next_x, next_y});
7944 for(
const auto &p: atlantic) {
7945 if(pacific.contains(p)) {
7946 vector
vec = {p.first, p.second};
7947 ans.emplace_back(
vec);
7950 sort(ans.begin(), ans.end());