Submission #116699

#TimeUsernameProblemLanguageResultExecution timeMemory
116699ZwariowanyMarcinBitaro the Brave (JOI19_ho_t1)C++14
100 / 100
329 ms113520 KiB
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


#define pb push_back
#define ld long double
#define fi first
#define se second
#define ll long long
#define ss(x) (int) x.size()
#define mp make_pair
#define FOR(i, n) for(int i = 1; n >= i; ++i)

using namespace std;
using namespace __gnu_pbds;
const int nax = 5005;

int n, m;
string s[nax];
int dol[nax][nax], prawo[nax][nax];
ll ans = 0;

int main() {
	
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin >> n >> m;
	for(int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	
	for(int i = m - 1; 0 <= i; --i) {
		for(int j = 0; j < n; ++j) {
			prawo[j][i] = prawo[j][i + 1] + (s[j][i + 1] == 'O');
		}
	}
	for(int i = n - 1; 0 <= i; --i) {
		for(int j = 0; j < m; ++j) {
			dol[i][j] = dol[i + 1][j] + (s[i + 1][j] == 'I');
		}
	}
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			ans += (dol[i][j] * prawo[i][j] * (s[i][j] == 'J'));
		}
	}
	cout << ans;
	
	
	
	
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...