一洛本谷通 @ 2021-09-11 14:45:49
#include<bits/stdc++.h>
using namespace std;
int a[105][105],r,c,ans,minn=5000000,m1,m2;
int maxxxx(int a,int b,int c,int d){
int aa=max(a,c),bb=max(b,d);
return max(aa,bb);
}
void f(int x,int y){
ans++;
if(a[x][y]==minn) return;
if(maxxxx(a[x+1][y],a[x][y+1],a[x-1][y],a[x][y-1])==a[x+1][y]){
f(x+1,y);
}
if(maxxxx(a[x+1][y],a[x][y+1],a[x-1][y],a[x][y-1])==a[x][y+1]){
f(x,y+1);
}
if(maxxxx(a[x+1][y],a[x][y+1],a[x-1][y],a[x][y-1])==a[x-1][y]){
f(x-1,y);
}
if(maxxxx(a[x+1][y],a[x][y+1],a[x-1][y],a[x][y-1])==a[x][y-1]){
f(x,y-1);
}
}
int main(){
cin>>r>>c;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin>>a[i][j];
if(a[i][j]>a[m1][m2]) m1=i,m2=j;
if(a[i][j]<minn) minn=a[i][j];
}
}
f(m1,m2);
cout<<ans;
}