#include <algorithm>
#include <iostream>
using namespace std;
const int N = 50000;
const int ddi[] = { -1, 1, 0, 0 };
const int ddj[] = { 0, 0, -1, 1 };
int *aa[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
int n, m; cin >> n >> m;
for (int i = 0; i < n; i++) {
aa[i] = new int[m];
for (int j = 0; j < m; j++)
cin >> aa[i][j];
}
int ans = 0;
for (int il = 0; il < n; il++)
for (int ir = il; ir < n; ir++)
for (int jl = 0; jl < m; jl++)
for (int jr = jl; jr < m; jr++) {
int i_ = il, j_ = jl;
for (int i = il; i <= ir; i++)
for (int j = jl; j <= jr; j++)
if (aa[i_][j_] < aa[i][j])
i_ = i, j_ = j;
int k = 0;
for (int i = i_, j = j_; ; ) {
k++, i_ = -1, j_ = -1;
for (int h = 0; h < 4; h++) {
int ih = i + ddi[h], jh = j + ddj[h];
if (il <= ih && ih <= ir
&& jl <= jh && jh <= jr
&& aa[ih][jh] < aa[i][j]
&& (i_ == -1 || aa[i_][j_] < aa[ih][jh]))
i_ = ih, j_ = jh;
}
if (i_ == -1 || aa[i][j] < aa[i_][j_])
break;
i = i_, j = j_;
}
if (k == (ir - il + 1) * (jr - jl + 1))
ans++;
}
cout << ans << '\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |