#include <bits/stdc++.h>
#define pb push_back
#define endl ("\n")
#define all(aa) aa.begin(), aa.end()
typedef long long ll;
using namespace std;
int main(){
int n, m;
cin >> n >> m;
vector<string> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
vector<vector<int>> suf(n, vector<int> (m + 1));
vector<vector<int>> asa(n, vector<int> (m + 1));
for(int i = 0; i < n; i++){
for(int j = m - 2; j >= 0; j--){
suf[i][j] = suf[i][j + 1] + (a[i][j + 1] == 'O');
}
}
for(int j = 0; j < m; j++){
for(int i = n - 2; i >= 0; i--){
asa[i][j] = asa[i + 1][j] + (a[i + 1][j] == 'I');
}
}
ll ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(a[i][j] == 'J'){
ans += suf[i][j] * asa[i][j];
}
}
}
cout << ans << endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |