This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
template<class T> using V = vector<T>;
using str = string;
using ll = long long;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, M; cin >> N >> M;
	V<str> A(N); for(auto& x : A) cin >> x;
	V<V<int>> I(N, V<int>(M, 0)), O(N, V<int>(M, 0));
	ll ans = 0;
	for(int i = N - 1; i >= 0; i--) for(int j = M - 1; j >= 0; j--) {
		I[i][j] = (A[i][j] == 'I');
		if (i+1 < N) I[i][j] += I[i+1][j];
		O[i][j] = (A[i][j] == 'O');
		if (j+1 < M) O[i][j] += O[i][j+1];
		if (A[i][j] == 'J') ans += O[i][j] * 1LL * I[i][j];
	}
	cout << ans << nl;
    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... |