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;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {
    return o << '(' << p.first << ", " << p.second << ')';
}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o) {
    o << '{';
    bool first = true;
    for (const auto& e : x) {
        if (!first) {
            o << ", ";
        }
        o << e;
        first = false;
    }
    return o << '}';
}
#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x) 
#endif
typedef long long ll;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
int tab[3010][3010];
int sumd[3010][3010];
int sump[3010][3010];
void solve() {
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		string c;
		cin >> c;
		for(int j = 1; j <= m; j++) {
			if(c[j - 1] == 'O') {
				tab[i][j] = 1;
			}
			if(c[j - 1] == 'I') {
				tab[i][j] = 2;
			}
		}
	}
	for(int j = 1; j <= m; j++) {
		for(int i = n; i >= 1; i--) {
			sumd[j][i] = sumd[j][i + 1];
			if(tab[i][j] == 2) {
				sumd[j][i]++;
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = m; j >= 1; j--) {
			sump[i][j] = sump[i][j + 1];
			if(tab[i][j] == 1) {
				sump[i][j]++;
			}
		}
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			if(!tab[i][j]) {
				ans += sump[i][j + 1] * sumd[j][i + 1];
			}
		}
	}
	cout << ans << '\n';
}
int main() {
	fastio();
	int t;
	//cin >> t;
	t = 1;	
	while(t--) {
		solve();
	}
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |