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;
using ll = long long;
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int>> cntI(n, vector<int>(m)), cntO(n, vector<int>(m));
for (int i = n - 1; i >= 0; i--) {
for (int j = m - 1; j >= 0; j--) {
cntI[i][j] += (i + 1 < n ? cntI[i + 1][j] : 0) + (a[i][j] == 'I');
cntO[i][j] += (j + 1 < m ? cntO[i][j + 1] : 0) + (a[i][j] == 'O');
}
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m - 1; j++) {
if (a[i][j] == 'J') ans += 1LL * cntO[i][j] * cntI[i][j];
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |