记录详情

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]
     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]
             scanf("%d",&a[i][j]);
             ~~~~~^~~~~~~~~~~~~~~
[Hydro](https://hydro.ac)提供评测服务
# 状态 耗时 内存占用
#1 Accepted 41ms 3.156 MiB
#2 Accepted 9ms 2.898 MiB
#3 Accepted 14ms 1.441 MiB
#4 Accepted 4ms 788.0 KiB
#5 Accepted 30ms 2.312 MiB
#6 Accepted 4ms 812.0 KiB
#7 Accepted 3ms 1.43 MiB
#8 Accepted 19ms 1.66 MiB
#9 Accepted 6ms 1.469 MiB
#10 Accepted 29ms 2.918 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-07-20 11:03:44
评测时间
2021-07-20 12:01:09
评测机
分数
100
总耗时
162ms
峰值内存
3.156 MiB