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;
const int N = 3003;
int cx[N][N], cy[N][N], n, m;
string g[N];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> g[i];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cx[i][j] = cy[i][j] = 0;
}
}
for (int i = 0; i < n; ++i) {
for (int j = m - 1; j >= 0; --j) {
cx[i][j] += cx[i][j + 1];
if (g[i][j] == 'O') cx[i][j]++;
}
}
for (int j = 0; j < m; ++j) {
for (int i = n - 1; i >= 0; --i) {
cy[i][j] += cy[i + 1][j];
if (g[i][j] == 'I') cy[i][j]++;
}
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (g[i][j] == 'J') {
ans += cx[i][j] * cy[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... |