Naxocist

Temperature is Rising [1061]

Apr 28th, 2022
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define INF 1e9
  5.  
  6. using ll = long long;
  7. using pi = pair<int, int>;
  8. using pii = pair<pi, int>;
  9.  
  10. const int N = 25;
  11. int ar[N][N], tr[] = {-1, 1, 0, 0}, tc[] = {0, 0, -1, 1};
  12. bool vis[N][N];
  13.  
  14. int main(){
  15.     ios_base::sync_with_stdio(false); cin.tie(nullptr);
  16.    
  17.     int n; cin >> n;
  18.     int x, y; cin >> y >> x;
  19.     for(int i=1; i<=n; ++i){
  20.         for(int j=1; j<=n; ++j) cin >> ar[i][j];
  21.     }
  22.  
  23.     queue<pi> q;
  24.  
  25.     vis[x][y] = 1;
  26.     int mx = ar[x][y];
  27.     q.push({x, y});
  28.  
  29.     while(q.size()){
  30.         pi f = q.front(); q.pop();
  31.         int r = f.first, c = f.second;
  32.  
  33.         for(int i=0; i<4; ++i){
  34.             int h = r + tr[i], k = c + tc[i];
  35.             if(h < 1 || k < 1 || h > n || k > n || ar[h][k] <= ar[r][c] || vis[h][k] || ar[h][k] == 100)
  36.                 continue;
  37.                
  38.             vis[h][k] = 1;
  39.             mx = max(mx, ar[h][k]);
  40.             q.push({h, k});
  41.         }
  42.     }
  43.     cout << mx;
  44.     return 0;
  45.  
  46. }
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment