记录详情

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 42ms 3.176 MiB
#2 Accepted 10ms 2.879 MiB
#3 Accepted 12ms 1.332 MiB
#4 Accepted 3ms 872.0 KiB
#5 Accepted 24ms 2.254 MiB
#6 Accepted 3ms 760.0 KiB
#7 Accepted 3ms 1.453 MiB
#8 Accepted 19ms 1.695 MiB
#9 Accepted 6ms 1.57 MiB
#10 Accepted 26ms 3.047 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:00:23
评测时间
2021-07-20 11:01:06
评测机
分数
100
总耗时
152ms
峰值内存
3.176 MiB