This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import sys
input=sys.stdin.readline
n,m=list(map(int,input().split()))
s=[]
for i in range(n):
s.append(list(input()))
c=0
for i in range(n+m-2):
j=min(i,m-1)
k=i-j
while k<n:
#print(i,k)
#print(s)
if j>=0 and j<m-2 and s[k][j]=="R" and s[k][j+1]=="G" and s[k][j+2]=="W":
c+=1
s[k][j]=""
s[k][j+1]=""
s[k][j+2]=""
k+=1
j-=1
elif j>=0 and k<n-2 and s[k][j]=="R" and s[k+1][j]=="G" and s[k+2][j]=="W":
q=k+1
#print(q,"aaa")
j-=1
while j>=0 and j<m-2 and q<n-2 and s[q][j]=="R" and s[q+1][j]=="G" and s[q+2][j]=="W" and s[q][j]=="R" and s[q][j+1]=="G" and s[q][j+2]=="W":
q+=1
j-=1
if j>=0 and q<n-2 and s[q][j]=="R" and s[q+1][j]=="G" and s[q+2][j]=="W":
c+=q-k
c+=1
s[q][j]=""
s[q+1][j]=""
s[q+2][j]=""
k=q+1
j-=1
elif j>=0 and j<m-2 and s[q][j]=="R" and s[q][j+1]=="G" and s[q][j+2]=="W":
c+=q-k
s[q][j]=""
s[q][j+1]=""
s[q][j+2]=""
k=q+1
j-=1
else:
c+=q-k
s[q+1][j+1]=""
k=q+1
j-=1
else:
k+=1
j-=1
#print(c,"cccc")
print(c)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |