#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 42
#endif
#define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> a(n);
vector<vector<int>> r(n, vector<int>(m));
vector<vector<int>> c(n, vector<int>(m));
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < m; j++) {
if (a[i][j] == 'O') {
r[i][j]++;
}
if (a[i][j] == 'I') {
c[i][j]++;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (j > 0) r[i][j] += r[i][j - 1];
if (i > 0) c[i][j] += c[i - 1][j];
}
}
int res = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == 'J') {
res += (r[i][m - 1] - r[i][j]) * (c[n - 1][j] - c[i][j]);
}
}
}
cout << res << '\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... |