#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int h, w;
cin >> h >> w;
string arr[h];
for (int i = 0; i < h; i++) cin >> arr[i];
vector<vector<ll>> prefO(h+1, vector<ll>(w+1, 0));
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
prefO[i][j] = prefO[i][j-1]+(arr[i-1][j-1] == 'O');
}
}
vector<vector<ll>> prefI(w+1, vector<ll>(h+1, 0));
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= h; j++) {
prefI[i][j] = prefI[i][j-1]+(arr[j-1][i-1] == 'I');
}
}
ll ans = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (arr[i-1][j-1] == 'J') {
ans += (prefO[i][w]-prefO[i][j])*(prefI[j][h]-prefI[j][i]);
}
}
}
cout << ans << endl;
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... |