Solution:
def replace(r,c,n,R,C):
count=0
for i in range(r-n,r+n+1):
for j in range(c-n,c+n+1):
if(i>=0 and i<R and j>=0 and j<C and a[i][j]!="#"):
a[i][j]="#"
count+=1
return count
r,c=map(int,input().split())
l=[]
a=[]
count=0
for i in range(r):
l.append(input().split())
a.append(["0" for i in range(c)])
for i in range(r):
for j in range(c):
if(l[i][j]=="S"):
count+=replace(i,j,1,r,c)
elif(l[i][j]=="L"):
count+=replace(i,j,2,r,c)
print(count)
Comment down if you have any doubts...
0 Comments