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;
const int N = 3e3 + 2;
int h , w , dpo[N][N] , dpi[N][N];
char c[N][N];
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);  cout.tie(0);
	cin >> h >> w;
	for(int i = 0 ; i < h ; i++)  for(int j = 0 ; j < w ; j++)
		cin >> c[i][j];
	long long ans = 0;
	for(int i = h - 1 ; i >= 0 ; i--)  for(int j = w - 1 ; j >= 0 ; j--)
	{
		dpi[i][j] = (i == h - 1 ? 0 : dpi[i + 1][j]);
		if(c[i][j] == 'I')
			dpi[i][j]++;
		dpo[i][j] = (j == w - 1 ? 0 : dpo[i][j + 1]);
		if(c[i][j] == 'O')
			dpo[i][j]++;
		if(c[i][j] == 'J')
			ans += dpi[i][j] * dpo[i][j];
	}
	cout << ans << '\n';
	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... |