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>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll n,m;
char a[3002][3002];
ll jewel[3002][3002];
ll orb[3002][3002];
ll ingot[3002][3002];
int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL); cout.tie(NULL);
   cin >> n >> m;
   for (ll i=1; i<=n; i++) {
      for (ll j=1; j<=m; j++) {
         cin >> a[i][j];
      }
   }
   memset(jewel,0,sizeof(jewel));
   memset(orb,0,sizeof(orb));
   memset(ingot,0,sizeof(ingot));
   //cout << "jewel: " << jewel[1][5] << endl;
   for (ll i=1; i<=n; i++) {
      for (ll j=m; j>=1; j--) {
         if (a[i][j]=='J') {
            //cout << i << " " << j << endl;
            jewel[i][j]=jewel[i][j+1]+1;
         } else {
            jewel[i][j]=jewel[i][j+1];
         }
      }
   }
   for (ll i=1; i<=n; i++) {
      for (ll j=m; j>=1; j--) {
         if (a[i][j]=='O') {
            orb[i][j]=orb[i][j+1]+1;
         } else {
            orb[i][j]=orb[i][j+1];
         }
      }
   }
   for (ll j=1; j<=m; j++) {
      for (ll i=n; i>=1; i--) {
         if (a[i][j]=='I') {
            ingot[i][j]=ingot[i+1][j]+1;
         } else {
            ingot[i][j]=ingot[i+1][j];
         }
      }
   }
//   for (ll i=1; i<=n; i++) {
//      for (ll j=1; j<=m; j++) {
//         cout << jewel[i][j] << " ";
//      }
//      cout << endl;
//   }
//   cout << endl;
//   for (ll i=1; i<=n; i++) {
//      for (ll j=1; j<=m; j++) {
//         cout << orb[i][j] << " ";
//      }
//      cout << endl;
//   }
//   cout << endl;
//   for (ll i=1; i<=n; i++) {
//      for (ll j=1; j<=m; j++) {
//         cout << ingot[i][j] << " ";
//      }
//      cout << endl;
//   }
//   cout << endl;
//   //cout << orb[2][2] << " " << ingot[3][1];
   ll ans=0;
   for (ll i=1; i<=n; i++) {
      for (ll j=1; j<=m; j++) {
         if (a[i][j]=='J') {
//            cout << i << " " << j << endl;
//            cout << orb[i][j+1] << " " << ingot[i+1][j] << endl;
//            cout << endl;
            ans+=(orb[i][j+1]*ingot[i+1][j]);
         }
      }
   }
   cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |