#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w;
if (!(cin >> h >> w)) return 0;
vector<string> a(h);
for (int i = 0; i < h; ++i) cin >> a[i];
vector<vector<int>> r(h, vector<int>(w, 0)), d(h, vector<int>(w, 0));
for (int i = 0; i < h; ++i) {
int c = 0;
for (int j = w - 1; j >= 0; --j) {
r[i][j] = c;
if (a[i][j] == 'O') ++c;
}
}
for (int j = 0; j < w; ++j) {
int c = 0;
for (int i = h - 1; i >= 0; --i) {
d[i][j] = c;
if (a[i][j] == 'I') ++c;
}
}
long long ans = 0;
for (int i = 0; i < h; ++i)
for (int j = 0; j < w; ++j)
if (a[i][j] == 'J') ans += 1LL * r[i][j] * d[i][j];
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |