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 |
1 |
Correct |
32 ms |
18204 KB |
Output is correct |
2 |
Correct |
33 ms |
18156 KB |
Output is correct |
3 |
Correct |
33 ms |
18132 KB |
Output is correct |
4 |
Correct |
37 ms |
18168 KB |
Output is correct |
5 |
Correct |
35 ms |
18192 KB |
Output is correct |
6 |
Correct |
33 ms |
18224 KB |
Output is correct |
7 |
Correct |
34 ms |
18228 KB |
Output is correct |
8 |
Correct |
37 ms |
18248 KB |
Output is correct |
9 |
Correct |
33 ms |
18204 KB |
Output is correct |
10 |
Correct |
33 ms |
18144 KB |
Output is correct |
11 |
Correct |
37 ms |
18220 KB |
Output is correct |
12 |
Correct |
33 ms |
18160 KB |
Output is correct |
13 |
Correct |
32 ms |
18212 KB |
Output is correct |
14 |
Correct |
32 ms |
18208 KB |
Output is correct |
15 |
Correct |
35 ms |
18216 KB |
Output is correct |
16 |
Correct |
33 ms |
18216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
18204 KB |
Output is correct |
2 |
Correct |
33 ms |
18156 KB |
Output is correct |
3 |
Correct |
33 ms |
18132 KB |
Output is correct |
4 |
Correct |
37 ms |
18168 KB |
Output is correct |
5 |
Correct |
35 ms |
18192 KB |
Output is correct |
6 |
Correct |
33 ms |
18224 KB |
Output is correct |
7 |
Correct |
34 ms |
18228 KB |
Output is correct |
8 |
Correct |
37 ms |
18248 KB |
Output is correct |
9 |
Correct |
33 ms |
18204 KB |
Output is correct |
10 |
Correct |
33 ms |
18144 KB |
Output is correct |
11 |
Correct |
37 ms |
18220 KB |
Output is correct |
12 |
Correct |
33 ms |
18160 KB |
Output is correct |
13 |
Correct |
32 ms |
18212 KB |
Output is correct |
14 |
Correct |
32 ms |
18208 KB |
Output is correct |
15 |
Correct |
35 ms |
18216 KB |
Output is correct |
16 |
Correct |
33 ms |
18216 KB |
Output is correct |
17 |
Correct |
33 ms |
18144 KB |
Output is correct |
18 |
Correct |
43 ms |
18152 KB |
Output is correct |
19 |
Correct |
34 ms |
18176 KB |
Output is correct |
20 |
Correct |
39 ms |
18188 KB |
Output is correct |
21 |
Correct |
37 ms |
18192 KB |
Output is correct |
22 |
Correct |
34 ms |
18216 KB |
Output is correct |
23 |
Correct |
33 ms |
18196 KB |
Output is correct |
24 |
Correct |
33 ms |
18224 KB |
Output is correct |
25 |
Correct |
33 ms |
18228 KB |
Output is correct |
26 |
Correct |
38 ms |
18312 KB |
Output is correct |
27 |
Correct |
38 ms |
18216 KB |
Output is correct |
28 |
Correct |
36 ms |
18208 KB |
Output is correct |
29 |
Correct |
37 ms |
18200 KB |
Output is correct |
30 |
Correct |
34 ms |
18132 KB |
Output is correct |
31 |
Correct |
34 ms |
18220 KB |
Output is correct |
32 |
Correct |
34 ms |
18132 KB |
Output is correct |
33 |
Correct |
34 ms |
18152 KB |
Output is correct |
34 |
Correct |
33 ms |
18148 KB |
Output is correct |
35 |
Correct |
34 ms |
18188 KB |
Output is correct |
36 |
Correct |
36 ms |
18180 KB |
Output is correct |
37 |
Correct |
33 ms |
18144 KB |
Output is correct |
38 |
Correct |
34 ms |
18224 KB |
Output is correct |
39 |
Correct |
37 ms |
18208 KB |
Output is correct |
40 |
Correct |
33 ms |
18220 KB |
Output is correct |
41 |
Correct |
34 ms |
18136 KB |
Output is correct |
42 |
Correct |
35 ms |
18176 KB |
Output is correct |
43 |
Correct |
34 ms |
18224 KB |
Output is correct |
44 |
Correct |
40 ms |
18148 KB |
Output is correct |
45 |
Correct |
34 ms |
18228 KB |
Output is correct |
46 |
Correct |
39 ms |
18156 KB |
Output is correct |
47 |
Correct |
36 ms |
18164 KB |
Output is correct |
48 |
Correct |
35 ms |
18228 KB |
Output is correct |
49 |
Correct |
34 ms |
18152 KB |
Output is correct |
50 |
Correct |
33 ms |
18208 KB |
Output is correct |
51 |
Correct |
33 ms |
18184 KB |
Output is correct |
52 |
Correct |
33 ms |
18184 KB |
Output is correct |
53 |
Correct |
36 ms |
18112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
18204 KB |
Output is correct |
2 |
Correct |
33 ms |
18156 KB |
Output is correct |
3 |
Correct |
33 ms |
18132 KB |
Output is correct |
4 |
Correct |
37 ms |
18168 KB |
Output is correct |
5 |
Correct |
35 ms |
18192 KB |
Output is correct |
6 |
Correct |
33 ms |
18224 KB |
Output is correct |
7 |
Correct |
34 ms |
18228 KB |
Output is correct |
8 |
Correct |
37 ms |
18248 KB |
Output is correct |
9 |
Correct |
33 ms |
18204 KB |
Output is correct |
10 |
Correct |
33 ms |
18144 KB |
Output is correct |
11 |
Correct |
37 ms |
18220 KB |
Output is correct |
12 |
Correct |
33 ms |
18160 KB |
Output is correct |
13 |
Correct |
32 ms |
18212 KB |
Output is correct |
14 |
Correct |
32 ms |
18208 KB |
Output is correct |
15 |
Correct |
35 ms |
18216 KB |
Output is correct |
16 |
Correct |
33 ms |
18216 KB |
Output is correct |
17 |
Correct |
33 ms |
18144 KB |
Output is correct |
18 |
Correct |
43 ms |
18152 KB |
Output is correct |
19 |
Correct |
34 ms |
18176 KB |
Output is correct |
20 |
Correct |
39 ms |
18188 KB |
Output is correct |
21 |
Correct |
37 ms |
18192 KB |
Output is correct |
22 |
Correct |
34 ms |
18216 KB |
Output is correct |
23 |
Correct |
33 ms |
18196 KB |
Output is correct |
24 |
Correct |
33 ms |
18224 KB |
Output is correct |
25 |
Correct |
33 ms |
18228 KB |
Output is correct |
26 |
Correct |
38 ms |
18312 KB |
Output is correct |
27 |
Correct |
38 ms |
18216 KB |
Output is correct |
28 |
Correct |
36 ms |
18208 KB |
Output is correct |
29 |
Correct |
37 ms |
18200 KB |
Output is correct |
30 |
Correct |
34 ms |
18132 KB |
Output is correct |
31 |
Correct |
34 ms |
18220 KB |
Output is correct |
32 |
Correct |
34 ms |
18132 KB |
Output is correct |
33 |
Correct |
34 ms |
18152 KB |
Output is correct |
34 |
Correct |
33 ms |
18148 KB |
Output is correct |
35 |
Correct |
34 ms |
18188 KB |
Output is correct |
36 |
Correct |
36 ms |
18180 KB |
Output is correct |
37 |
Correct |
33 ms |
18144 KB |
Output is correct |
38 |
Correct |
34 ms |
18224 KB |
Output is correct |
39 |
Correct |
37 ms |
18208 KB |
Output is correct |
40 |
Correct |
33 ms |
18220 KB |
Output is correct |
41 |
Correct |
34 ms |
18136 KB |
Output is correct |
42 |
Correct |
35 ms |
18176 KB |
Output is correct |
43 |
Correct |
34 ms |
18224 KB |
Output is correct |
44 |
Correct |
40 ms |
18148 KB |
Output is correct |
45 |
Correct |
34 ms |
18228 KB |
Output is correct |
46 |
Correct |
39 ms |
18156 KB |
Output is correct |
47 |
Correct |
36 ms |
18164 KB |
Output is correct |
48 |
Correct |
35 ms |
18228 KB |
Output is correct |
49 |
Correct |
34 ms |
18152 KB |
Output is correct |
50 |
Correct |
33 ms |
18208 KB |
Output is correct |
51 |
Correct |
33 ms |
18184 KB |
Output is correct |
52 |
Correct |
33 ms |
18184 KB |
Output is correct |
53 |
Correct |
36 ms |
18112 KB |
Output is correct |
54 |
Correct |
41 ms |
18988 KB |
Output is correct |
55 |
Correct |
74 ms |
20000 KB |
Output is correct |
56 |
Correct |
74 ms |
21084 KB |
Output is correct |
57 |
Correct |
92 ms |
22092 KB |
Output is correct |
58 |
Correct |
300 ms |
63268 KB |
Output is correct |
59 |
Runtime error |
549 ms |
262144 KB |
Execution killed with signal 9 |
60 |
Halted |
0 ms |
0 KB |
- |