This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
n,m=list(map(int,input().split()))
s=[]
for i in range(n):
v=list(input())
ss=[]
for p in v:
if p=="R":
ss.append(1)
elif p=="G":
ss.append(2)
else:
ss.append(3)
s.append(ss)
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]==1 and s[k][j+1]==2 and s[k][j+2]==3:
c+=1
s[k][j]=0
s[k][j+1]=0
s[k][j+2]=0
k+=1
j-=1
elif j>=0 and k<n-2 and s[k][j]==1 and s[k+1][j]==2 and s[k+2][j]==3:
q=k+1
#print(q,"aaa")
j-=1
while j>=0 and j<m-2 and q<n-2 and s[q][j]==1 and s[q+1][j]==2 and s[q+2][j]==3 and s[q][j+1]==2 and s[q][j+2]==3:
q+=1
j-=1
if j>=0 and q<n-2 and s[q][j]==1 and s[q+1][j]==2 and s[q+2][j]==3:
c+=q-k
c+=1
s[q][j]=0
s[q+1][j]=0
s[q+2][j]=0
k=q+1
j-=1
elif j>=0 and j<m-2 and s[q][j]==1 and s[q][j+1]==2 and s[q][j+2]==3:
c+=q-k
s[q][j]=0
s[q][j+1]=0
s[q][j+2]=0
k=q+1
j-=1
else:
c+=q-k
s[q+1][j+1]=0
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... |