This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 3e3 + 5;
ll h, w;
string a [MAXN];
ll sat [MAXN][MAXN];
ll nol [MAXN][MAXN];
int main(){
    cin >> h >> w;
    for(ll i = 1; i <= h; i++){
        cin >> a[i];
    }
    for(ll i = 1; i <= h; i++){
        for(ll j = w-1; j >= 0; j--){
            nol[i][j] = nol[i][j+1];
            if(a[i][j] == 'O'){
                nol[i][j]++;
            }
        }
    }
    for(ll j = 0; j < w; j++){
        for(ll i = h; i >= 1; i--){
            sat[i][j] = sat[i+1][j];
            if(a[i][j] == 'I'){
                sat[i][j]++;
            }
        }
    }
    ll ans = 0;
    for(ll i = 1; i <= h; i++){
        for(ll j = 0; j < w; j++){
            if(a[i][j] == 'J'){
                ans += sat[i][j] * nol[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... |