이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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... |