记录详情

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 39ms 4.312 MiB
#2 Accepted 9ms 3.043 MiB
#3 Accepted 13ms 1.746 MiB
#4 Accepted 3ms 788.0 KiB
#5 Accepted 24ms 3.039 MiB
#6 Accepted 3ms 852.0 KiB
#7 Accepted 4ms 1.508 MiB
#8 Accepted 19ms 2.227 MiB
#9 Accepted 9ms 1.75 MiB
#10 Accepted 28ms 4.184 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-24 12:32:24
评测时间
2021-07-24 12:32:24
评测机
分数
100
总耗时
154ms
峰值内存
4.312 MiB