#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int h,w;
cin>>h>>w;
int a[h+5][w+5];
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
cin>>a[i][j];
}
}
vector<int>dx={0,0,-1,1};
vector<int>dy={-1,1,0,0};
int ans=0;
for(int x1=1;x1<=h;x1++){
for(int y1=1;y1<=w;y1++){
for(int x2=x1;x2<=h;x2++){
for(int y2=y1;y2<=w;y2++){
int tot=0,mx=0,x=0,y=0;
for(int i=x1;i<=x2;i++){
for(int j=y1;j<=y2;j++){
if(a[i][j]>mx){
mx=a[i][j];
x=i;
y=j;
}
}
}
int xx,yy;
while(true){
tot++;
int L=0;
for(int k=0;k<4;k++){
int nx=x+dx[k],ny=y+dy[k];
if(nx<x1||ny<y1||nx>x2||ny>y2) continue;
if(a[nx][ny]>L&&a[nx][ny]<a[x][y]){
L=a[nx][ny];
xx=nx;
yy=ny;
}
}
if(L==0) break;
x=xx,y=yy;
}
if(tot==(x2-x1+1)*(y2-y1+1)){
ans++;
}
}
}
}
}
cout<<ans;
}
# | 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... |