#include <bits/stdc++.h>
#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))
constexpr bool dbg = 1;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl
#define ll long long
#define pb push_back
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> v(n);
rep(i, 0, n) cin >> v[i];
vector<vector<ll>> cntO(n, vector<ll>(m)), cntI(n, vector<ll>(m));
rep(i, 0, n) {
cntO[i][m - 1] = v[i][m - 1] == 'O';
repD(j, m - 2, -1) cntO[i][j] = cntO[i][j + 1] + (v[i][j] == 'O');
}
rep(j, 0, m) {
cntI[n - 1][j] = v[n - 1][j] == 'I';
repD(i, n - 2, -1) cntI[i][j] = cntI[i + 1][j] + (v[i][j] == 'I');
}
ll ans = 0;
rep(i, 0, n) rep(j, 0, m) if(v[i][j] == 'J') ans += cntO[i][j] * cntI[i][j];
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |