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;
#define int long long
signed main() {
    //your code goes here
    int n, m;
    cin >> n >> m;
    vector <vector <int>> arr(n, vector <int>(m));
    vector <vector <int>> pref(n, vector <int>(m));
    vector <vector <int>> pref2(n, vector <int>(m));
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < m; j++) {
            if(s[j] == 'J') {
                arr[i][j] = 1;
            } else if(s[j] == 'O') {
                arr[i][j] = 2;
            } else {
                arr[i][j] = 3;
            }
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = m-1; j >= 0; j--) {
            if(arr[i][j] == 2) {
                pref[i][j] += 1;
            }
            if(j == m-1) {
                continue;
            }
            pref[i][j] += pref[i][j+1];
        }
    }
    for(int i = 0; i < m; i++) {
        for(int j = n-1; j >= 0; j--) {
            if(arr[j][i] == 3) {
                pref2[j][i] += 1;
            }
            if(j == n-1) {
                continue;
            }
            pref2[j][i] += pref2[j+1][i];
        }
    }
    int total = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(arr[i][j] == 1) {
                int val1 = pref[i][j];
                int val2 = pref2[i][j];
                // cout << val1 << " " << val2 << " " << i << " " << j << endl;
                total += (val1*val2);
            }
        }
    }
    cout << total << endl;
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |