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
#define pb push_back
#define ld long double
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> A(n);
for (int i = 0; i < n; i++) cin >> A[i];
int ans = 0;
vector<vector<int>> suf_o(n + 1, vector<int>(m+1));
vector<vector<int>> stolb_i(n + 1, vector<int>(m+1));
for (int i = 0; i < n; i++) {
suf_o[i][m-1] = (A[i][m-1] == 'O');
for (int j = m - 2; j >= 0; j--) {
suf_o[i][j] = (A[i][j]=='O') + suf_o[i][j+1];
}
}
for (int j = 0; j < m; j++) {
stolb_i[n-1][j] = (A[n-1][j] == 'I');
for (int i = n - 2; i >= 0; i--) {
stolb_i[i][j] = stolb_i[i+1][j] + (A[i][j] == 'I');
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (A[i][j] == 'J') {
ans += suf_o[i][j+1] * stolb_i[i+1][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... |