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>
#define int long long
#define endl '\n'
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> arr(n);
for (auto &x : arr) {
cin >> x;
}
vector<vector<int>> O(n, vector<int>(m)), I(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[i][j] == 'O') {
O[i][j]++;
} else if (arr[i][j] == 'I') {
I[i][j]++;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = m - 2; j >= 0; j--) {
O[i][j] += O[i][j + 1];
}
}
for (int j = 0; j < m; j++) {
for (int i = n - 2; i >= 0; i--) {
I[i][j] += I[i + 1][j];
}
}
int res = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[i][j] == 'J') {
res += O[i][j] * I[i][j];
}
}
}
cout << res << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |