记录详情

Accepted

foo.cc: In function 'int main()':
foo.cc:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
foo.cc:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |             scanf("%d",&a[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~
正在同步测试数据,请稍后
[Hydro](https://hydro.ac)提供评测服务
# 状态 耗时 内存占用
#1 Accepted 58ms 3.117 MiB
#2 Accepted 13ms 2.875 MiB
#3 Accepted 17ms 1.375 MiB
#4 Accepted 4ms 768.0 KiB
#5 Accepted 29ms 2.367 MiB
#6 Accepted 3ms 768.0 KiB
#7 Accepted 4ms 1.375 MiB
#8 Accepted 27ms 1.625 MiB
#9 Accepted 14ms 1.5 MiB
#10 Accepted 29ms 2.992 MiB

代码

#include <stdio.h>
#include <algorithm>
using namespace std;

int n,m;
int a[505][505];
int dp[505][505];
int vis[505][505];
int ans;

int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

int dfs(int x,int y)
{
    if(vis[x][y]) return dp[x][y];
    vis[x][y]=1;
    int flag=0;
    for(int i=0;i<4;i++)
    {
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx<1 || nx>n || ny<1 || ny>m || a[nx][ny]>=a[x][y]) continue;
        flag=1;
        dp[x][y]=max(dp[x][y],dfs(nx,ny)+1);
    }
    if(flag==0) dp[x][y]=1;
    ans=max(ans,dp[x][y]);
    return dp[x][y];
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%d",&a[i][j]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            dfs(i,j);
    printf("%d",ans);
    return 0;
}

信息

递交者
类型
递交
题目
P1009 清帝之惑之顺治
语言
C++
递交时间
2021-12-30 16:01:34
评测时间
2021-12-30 16:01:34
评测机
分数
100
总耗时
201ms
峰值内存
3.117 MiB