谭之荔 @ 2019-08-20 14:02:59
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int tot,mx;
int a[1005][1005],f[1005][1005];
struct A
{
int v,x,y;
}b[10005];
bool cmp(A o,A p)
{
if(o.v==p.v) return o.x<p.x;
return o.v>p.v;
}
int main()
{
int m,n;
cin>>m>>n;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
b[++tot].x=i;
b[tot].y=j;
b[tot].v=a[i][j];
}
}
sort(b+1,b+1+tot,cmp);
for(int i=1;i<=tot;i++)
{
f[b[i].x][b[i].y]=max(max(f[b[i].x-1][b[i].y],f[b[i].x+1][b[i].y]),max(f[b[i].x][b[i].y-1],f[b[i].x][b[i].y+1]))+1;
}
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
{
mx=max(mx,f[i][j]);
}
}
cout<<mx;
}