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 = map(int, input().split())
a = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
d1 = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
d2 = [[0 for _ in range(m + 1)] for _ in range(n + 1)]
for i in range(1, n + 1) :
s = input()
for j in range(1, m + 1) :
a[i][j] = 0 if s[j - 1] == 'J' else 1 if s[j - 1] == 'O' else 2
ans = 0
for i in range(n, 0, -1) :
for j in range(m, 0, -1) :
d1[i][j] = (a[i][j] == 1) + (0 if j == m else d1[i][j + 1])
d2[i][j] = (a[i][j] == 2) + (0 if i == n else d2[i + 1][j])
if a[i][j] == 0 :
ans += d1[i][j] * d2[i][j]
print(ans)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |