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;
char mp[3000][3000];
int n, m, cc[2][3000][3000];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> mp[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (mp[i][j] == 'O')
cc[0][i][j]++;
else if (mp[i][j] == 'I')
cc[1][i][j]++;
else;
for (int i = 0; i < n; i++)
for (int j = m - 2; j >= 0; j--)
cc[0][i][j] += cc[0][i][j + 1];
for (int j = 0; j < m; j++)
for (int i = n - 2; i >= 0; i--)
cc[1][i][j] += cc[1][i + 1][j];
long long ans = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (mp[i][j] == 'J')
ans += (long long)cc[0][i][j] * cc[1][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... |