Python 第二个测试点 神奇的RE

P1434 [SHOI2002] 滑雪

时光倒流zhu @ 2020-02-24 10:28:53

n,m=map(int,input().split())
area=[list(map(float,input().split())) for _ in range(n)]
p=[] # 顶点搜索
for i in range(n):
    for j in range(m):
        if (i<=0 or area[i-1][j]<=area[i][j]) and \
                (n-1<=i or area[i+1][j]<=area[i][j]) and \
                (j<=0 or area[i][j-1]<=area[i][j]) and \
                (m-1<=j or area[i][j+1]<=area[i][j]):
            p.append((i,j))
ans=float('-inf')
action=[(0,1),(0,-1),(1,0),(-1,0)]
def dfs(i,j,count):
    global ans
    flag=1
    for ny,nx in action:
        if 0<=i+ny<n and 0<=j+nx<m and area[i][j]>area[i+ny][j+nx]:
            dfs(i+ny,j+nx,count+1)
            flag=0
    if flag:
        ans=max(ans,count)
for y,x in p:
    dfs(y,x,1)
print(ans)

真的看不出有什么问题


by zexuan_k @ 2020-03-22 13:49:29

我也第二个点RE,同求


by irisjiel @ 2022-04-25 09:28:44

Python3 的函数递归调用深度限制是 1000 层,#2 测试点的调用深度超过了 1000,因此会 RE。

sys.setrecursionlimit 方法,将递归深度设置大一些即可。我刚才也报错,设置成 10005 后就过了。


|