#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define vodka void
#define ertunt return
using namespace std;
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll h, w;
cin >> h >> w;
vector<string> s(h);
vector<ll> J(h + 5,0), O(h + 5,0), I(w + 5,0);
for (ll i = 0; i < h; i++) {
cin >> s[i];
for (ll j = 0; j < w; j++) {
if (s[i][j] == 'O') O[i]++;
}
}
for (ll i = 0; i < w; i++) {
for (ll j = 0; j < h; j++) {
if (s[j][i] == 'I') I[i]++;
}
}
ll ans = 0;
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++) {
if (s[i][j] == 'J') {
ans+=I[j]*O[i];
}
if (s[i][j] == 'O') O[i]--;
if (s[i][j] == 'I') I[j]--;
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |