#include <bits/stdc++.h>
#define int long long
using namespace std;
string a[3005];
int fi[3005][3005];
int fo[3005][3005];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 1;i <= n;i++) {
cin >> a[i];
string s = " ";
a[i] = s + a[i];
}
for (int i = 1;i<=n;i++){
for (int j = 1; j <= m;j++) {
fo[i][j] = fo[i][j-1] + (a[i][j] == 'O');
fi[i][j] = fi[i-1][j] + (a[i][j] == 'I');
// cout << i << " " << j << '\n';
// cout << fo[i][j] << " " << fi[i][j] << '\n';
}
}
int res = 0;
for (int i = 1;i<=n;i++) {
for (int j = 1;j<=m;j++) {
if (a[i][j] == 'J') res += (fi[n][j] - fi[i][j]) * (fo[i][m] - fo[i][j]);
// cout << fi[n][j] - fi[i][j] << " " << fo[i][m] - fo[i][j] << '\n';
}
}
cout << res;
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... |