This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
H, W = map(int, input().split())
grid = []
for i in range(H):
grid.append(list(input()))
## grid[h][w]
grido = [[0 for i in range(W+1)] for j in range(H+1)] ## rows
gridi = [[0 for i in range(W+1)] for j in range(H+1)] ## cols
## o
for row in range(H):
for col in range(W-1, -1, -1):
num = (grid[row][col] == "O")
grido[row][col] = grido[row][col+1] + num
## i
for col in range(W):
for row in range(H-1, -1, -1):
num = (grid[row][col] == "I")
gridi[row][col] = gridi[row+1][col] + num
ans = 0
for row in range(H):
for col in range(W):
if grid[row][col] == "J":
ans += grido[row][col+1] * gridi[row+1][col]
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... |