#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
vector<string> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = " " + a[i];
}
vector<vector<ll>> xeto(n + 2, vector<ll>(m + 2, 0));
vector<vector<ll>> xeti(n + 2, vector<ll>(m + 2, 0));
for (int i = 1; i <= n; i++) {
for (int j = m; j >= 1; j--) {
xeto[i][j] = xeto[i][j + 1] + (a[i][j] == 'O');
}
}
for (int j = 1; j <= m; j++) {
for (int i = n; i >= 1; i--) {
xeti[i][j] = xeti[i + 1][j] + (a[i][j] == 'I');
}
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
ans += xeto[i][j] * xeti[i][j] * (a[i][j] == 'J');
}
}
cout << ans << "\n";
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... |