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;
#define int long long
typedef pair<int, int> pii;
const int MXN = 5005;
int n, m, O[MXN][MXN], I[MXN][MXN], ans;
string s[MXN];
char c[MXN][MXN];
void GO() {
for (int i = 0; i < n; i++) {
for (int j = m - 2; j >= 0; j--) {
O[i][j] = O[i][j + 1];
if (s[i][j + 1] == 'O') O[i][j]++;
}
}
}
void GI() {
for (int j = 0; j < m; j++) {
for (int i = n - 2; i >= 0; i--) {
I[i][j] = I[i + 1][j];
if (s[i + 1][j] == 'I') I[i][j]++;
}
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> s[i];
GO();
GI();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] != 'J') continue;
ans += O[i][j] * I[i][j];
}
}
cout << ans << endl;
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... |