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