fork download
  1. /*
  2.   author : [ Godsent ]
  3.   created : 2025.11.17 13:52:57
  4. */
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. #include <ext/pb_ds/assoc_container.hpp>
  9. #include <ext/pb_ds/tree_policy.hpp>
  10. #define el '\n'
  11. #define int long long
  12. #define lb lower_bound
  13. #define ub upper_bound
  14. #define fi first
  15. #define se second
  16. #define sz(x) ((int)(x).size())
  17. #define all(v) (v).begin(), (v).end()
  18. #define pb push_back
  19. #define prs(n) fixed << setprecision(n)
  20.  
  21. const int mod = 1e9 + 7;
  22. const int N = 1e3 + 5;
  23. const int INF = 1e18;
  24.  
  25. using namespace std;
  26. using namespace __gnu_pbds;
  27. template <typename T>
  28. using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  29.  
  30. int n, m;
  31. int a[N][N], used[N][N];
  32.  
  33. void Solve() {
  34. cin >> n >> m;
  35. for (int i = 1; i <= n; i++) {
  36. for (int j = 1; j <= m; j++) cin >> a[i][j];
  37. }
  38.  
  39. if (n == 1 || m == 1) {
  40. cout << n * m << el;
  41. return;
  42. }
  43.  
  44. int res = n * 2 + (m - 2) * 2;
  45. for (int i = 2; i < n; i++) {
  46. for (int j = 2; j < m; j++) {
  47. int oke = 0;
  48. // cout << a[i][j] << ' ';
  49. for (int k = j + 1; k <= m; k++) {
  50. if (a[i][j] <= a[i][k]) break;
  51. // cout << a[i][k] << ' ';
  52. if (k == m) oke = 1;
  53. }
  54. for (int k = j - 1; k > 0; k--) {
  55. if (a[i][j] <= a[i][k]) break;
  56. // cout << a[i][j] << ' ' << a[i][k] << el;
  57. if (k == 1) oke = 1;
  58. }
  59. for (int k = i + 1; k <= n; k++) {
  60. if (a[i][j] <= a[k][j]) break;
  61. if (k == n) oke = 1;
  62. }
  63. for (int k = i - 1; k > 0; k--) {
  64. if (a[i][j] <= a[k][j]) break;
  65. if (k == 1) oke = 1;
  66. }
  67. if (oke) res++;
  68. }
  69. }
  70. cout << res << el;
  71. }
  72.  
  73. signed main() {
  74. ios_base::sync_with_stdio(false);
  75. cin.tie(0);
  76. cout.tie(0);
  77.  
  78. #ifndef ONLINE_JUDGE
  79. freopen("test.in", "r", stdin);
  80. freopen("test.out", "w", stdout);
  81. #endif
  82.  
  83. int t = 1;
  84. // cin >> t;
  85. while (t--) Solve();
  86.  
  87. return 0;
  88. }
  89.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
-4