比赛 防止浮躁的小练习v0.2 评测结果 AAAAAAAAAA
题目名称 最长滑坡 最终得分 100
用户昵称 Mealy 运行时间 0.312 s
代码语言 C++ 内存使用 4.92 MiB
提交时间 2016-10-08 10:30:37
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int nmax=520;
class point
{
public:
	int x,y;
	int val;
}poi[nmax*nmax];
int nn,nm;
int cnt=0;
int out=0;
int res[nmax][nmax]={0};
int ans[nmax][nmax]={0};
bool cmp(point a,point b)
{
	return a.val<b.val;
}
void PreDo()
{
	scanf("%d%d",&nn,&nm);
	for(int i=1;i<=nn;i++)
		for(int j=1;j<=nm;j++)
		{
			scanf("%d",&res[i][j]);
			poi[++cnt].x=i;
			poi[cnt].y=j;
			poi[cnt].val=res[i][j];
		}
	sort(poi+1,poi+cnt+1,cmp);
	for(int i=1;i<=cnt;i++)
	{
		if(poi[i].x-1>0)
			if(res[poi[i].x-1][poi[i].y]>poi[i].val)
				ans[poi[i].x-1][poi[i].y]=max(ans[poi[i].x][poi[i].y]+1,ans[poi[i].x-1][poi[i].y]);
		if(poi[i].y-1>0)
			if(res[poi[i].x][poi[i].y-1]>poi[i].val)
				ans[poi[i].x][poi[i].y-1]=max(ans[poi[i].x][poi[i].y]+1,ans[poi[i].x][poi[i].y-1]);
		if(poi[i].x+1<=nn)
			if(res[poi[i].x+1][poi[i].y]>poi[i].val)
				ans[poi[i].x+1][poi[i].y]=max(ans[poi[i].x][poi[i].y]+1,ans[poi[i].x+1][poi[i].y]);
		if(poi[i].y+1<=nm)
			if(res[poi[i].x][poi[i].y+1]>poi[i].val)
				ans[poi[i].x][poi[i].y+1]=max(ans[poi[i].x][poi[i].y]+1,ans[poi[i].x][poi[i].y+1]);
	}
	for(int i=1;i<=nn;i++)
	{
		for(int j=1;j<=nm;j++)
		{
			if(out<ans[i][j])
				out=ans[i][j];
			//printf("%d ",ans[i][j]);
		}
		//printf("\n");
	}
	
	printf("%d\n",out+1);
}
int main()
{
	freopen("shunzhi.in","r",stdin);
	freopen("shunzhi.out","w",stdout);
	PreDo();
	return 0;
}