#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int H, W;
cin >> H >> W;
string s[H];
int cnto[H][W] {}, cnti[H][W] {};
for(int i = 0; i < H; i++) {
cin >> s[i];
for(int j = 0; j < W; j++) {
if(j != 0) cnto[i][j] = cnto[i][j - 1];
if(i != 0) cnti[i][j] = cnti[i - 1][j];
if(s[i][j] == 'O') cnto[i][j]++;
else if(s[i][j] == 'I') cnti[i][j]++;
}
}
ll ans = 0;
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
if(s[i][j] == 'J') {
ans += 1LL * (cnto[i][W - 1] - cnto[i][j]) * (cnti[H - 1][j] - cnti[i][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... |