Advertisement
wym1111

Untitled

Mar 2nd, 2024
1,296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 110;
  5.  
  6. int n, m;
  7. int a[N][N];
  8.  
  9. /*
  10.   A B C
  11.   D o E
  12.   F G H
  13.   o (x, y)
  14.   F (x + 1, y - 1)
  15.  */
  16.  
  17. int dx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; // F G H A B C D E
  18. int dy[8] = {-1, 0, 1, -1, 0, 1, -1, 1};
  19.  
  20. signed main() {
  21.     cin >> n >> m;
  22.     for (int i = 1; i <= n; i ++) {
  23.         for (int j = 1; j <= m; j ++) {
  24.             cin >> a[i][j];
  25.         }
  26.     }
  27.     int ans = 0;
  28.     for (int x = 1; x <= n; x ++) {
  29.         for (int y = 1; y <= m; y ++) {
  30.             bool flag = 1;
  31.             // (x, y)
  32.             for (int i = 0; i < 8; i ++) {
  33.                 int nx = dx[i] + x;
  34.                 int ny = dy[i] + y;
  35.                 // (nx, ny)
  36.                 if (nx < 1 || nx > n || ny < 1 || ny > m) continue;
  37.                 if (a[x][y] < a[nx][ny]) {
  38.                     flag = 0;
  39.                 }
  40.             }
  41.             if (flag) ans ++;
  42.         }
  43.     }
  44.     cout << ans << endl;
  45.     return 0;
  46. }
  47.  
  48. /*
  49.     0   0   0   0   0   0
  50.  
  51.     0  150 190 170 180  0
  52.  
  53.     0  145 150 165 175  0
  54.  
  55.     0  140 178 149 190
  56.  
  57.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement