求助,为什么过不了
https://ac.nowcoder.com/acm/problem/266841
n,m=map(int,input().split()) mp=[list(input()) for _ in range(n)] vis=[[False]*1005 for _ in range(1005)] l,r,u,b=m,0,0,n cnt=0 ans=0 def dfs (x,y): global l,r,u,b,cnt l=min(l,y) r=max(r,y) u=max(u,x) b=min(b,x) cnt+=1 vis[x][y]=True for i,j in [(x+1,y),(x,y+1),(x-1,y),(x,y-1)]: if 0<=i<n and 0<=j<m and vis[i][j]!=True: dfs(i,j) for i in range(n) : for j in range(m) : if mp[i][j]=="*": vis[i][j]=True for i in range(n) : for j in range(m) : l,r,u,b=m,0,0,n cnt=0 if vis[i][j]==0: dfs(i,j) if (r-l+1)*(u-b+1)==cnt : ans+=1 print(ans)