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 ll long long
const int N = 3005;
int main(){
	int h, w;
	ll sum = 0;
	ll zerocount, onecount;
	vector<string> grid;
	string input;
	ll pref0[N][N], pref1[N][N];
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		cin >> input;
		grid.push_back(input);
	}
	for(int i = 0; i < N-2; i++){
		for(int j = 0; j < N-2; j++){
			pref1[i][j] = 0;
			pref0[i][j] = 0;
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(grid[i][j] == 'O'){
				pref0[i][j]++;
			}
			else if(grid[i][j] == 'I'){
				pref1[i][j]++;
			}
		}
	}
	
	for(int i = 0; i < h; i++){
		for(int j = 1; j < w; j++){
			pref0[i][j] += pref0[i][j-1];
		}
	}
	for(int i = 1; i < h; i++){
		for(int j = 0; j < w; j++){
			pref1[i][j] += pref1[i-1][j];
		}
	}
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(grid[i][j] == 'J'){
				// cout << i << " " << j << endl;
				zerocount = pref0[i][w-1] - pref0[i][j];
				onecount = pref1[h-1][j] - pref1[i][j];
				sum += zerocount*onecount;
			}
		}
	}
	cout << sum << 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... |