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>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
const int inf = 2e9+1;
const int mod = 1e9+7;
const int maxn = 3010;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
string grid[maxn];
ll suf1[maxn][maxn], suf2[maxn][maxn];
int main(){_
    int h,w;cin>>h>>w;    
    for(int i=0;i<h;++i)cin>>grid[i];
    ll ans = 0;
    for(int i=h-1;~i;--i){
        for(int j=w-1;~j;--j){
            suf1[i][j] = suf1[i][j+1] + (grid[i][j]=='O');
            suf2[i][j] = suf2[i+1][j] + (grid[i][j]=='I');
        }
    }
    for(int i=0;i<h;++i)
        for(int j=0;j<w;++j)
            if(grid[i][j]=='J')ans += suf1[i][j]*suf2[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... |