#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define int long long
#define fi first
#define se second
const int N = 3e3 + 5, M = 1e9 + 7, LG = 20;
int n , m, dp[N][N] , pr[N][N];
char gr[N][N];
void solve(){
cin >> n >> m;
for (int i=1 ; i<=n ; i++){
for (int j=1 ; j<=m ; j++){
cin >> gr[i][j];
}
}
for (int i=n ; i>0 ; i--){
for (int j=m ; j>0 ; j--){
dp[i][j] = dp[i][j+1] + (gr[i][j] == 'O');
pr[i][j] = pr[i+1][j] + (gr[i][j] == 'I');
}
}
int ans = 0;
for (int i=1 ; i<=n ; i++){
for (int j=1 ; j<=m ; j++){
if (gr[i][j] == 'J') ans += (dp[i][j] * pr[i][j]);
}
}
cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int ts = 1;
// cin >> ts;
while(ts--){
solve();
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |