#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<vector<ll>> J(h + 5), O(h + 5), I(w + 5);
for (ll i = 0; i < h; i++) {
cin >> s[i];
for (ll j = 0; j < w; j++) {
if (s[i][j] == 'O') O[i].pb(j);
}
}
for (ll i = 0; i < w; i++) {
for (ll j = 0; j < h; j++) {
if (s[j][i] == 'I') I[i].pb(j);
}
}
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].size()*O[i].size();
}
if (s[i][j] == 'O') O[i].erase(find(all(O[i]), j));
if (s[i][j] == 'I') I[j].erase(find(all(I[j]), i));
}
}
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... |