#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char a[3005][3005];
int dem[3005][3005];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int H, W;
cin >> H >> W;
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
cin >> a[i][j];
}
}
for (int j = 1; j <= W; j++) {
int cur = 0;
for (int i = H; i >= 1; i--) {
dem[i][j] = cur;
if (a[i][j] == 'I') cur++;
}
}
ll ans = 0;
for (int i = 1; i < H; i++) {
ll sum = 0;
for (int j = 1; j <= W; j++) {
if (a[i][j] == 'J') {
sum += dem[i][j];
}
if (a[i][j] == 'O') {
ans += sum;
}
}
}
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... |