#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 500005
int tc = 1, n, a[N], ans, m;
string s[N];
int32_t main() {
ios::sync_with_stdio(0);cin.tie(0);
cin >> n >> m;
vector <vector <int>> O(n + 5, vector <int> (m + 5, 0));
for(int i = 1; i <= n; i++) {
cin >> s[i];
s[i] = '.' + s[i];
}
for(int i = 1; i <= n; i++) {
for(int j = m; j >= 1; j--) {
O[i][j] = O[i][j + 1] + (s[i][j] == 'O');
}
}
for(int i=1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(s[i][j] == 'J') {
for(int k = i + 1; k <= n; k++) {
if(s[k][j] == 'I') {
ans += (O[i][j]);
// cout << i << " " << j << " " << k << " " << l << '\n';
}
}
}
}
}
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... |