#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int H, W;
cin >> H >> W;
vector<string> grid(H);
for (int i = 0; i < H; ++i) {
cin >> grid[i];
}
vector<vector<int>> countI(H + 1, vector<int>(W, 0));
for (int j = 0; j < W; ++j) {
for (int i = H - 1; i >= 0; --i) {
countI[i][j] = countI[i + 1][j] + (grid[i][j] == 'I');
}
}
long long result = 0;
for (int i = 0; i < H; ++i) {
for (int k = i + 1; k < H; ++k) {
vector<int> prefixO(W + 1, 0);
for (int j = 0; j < W; ++j) {
prefixO[j + 1] = prefixO[j] + (grid[i][j] == 'O') + (grid[k][j] == 'O');
}
long long totalJ = 0;
for (int j = 0; j < W; ++j) {
if (grid[i][j] == 'J') {
totalJ += countI[k + 1][j];
}
if (grid[i][j] == 'O') {
result += totalJ * (prefixO[W] - prefixO[j + 1]);
}
}
}
}
cout << result+1 << endl;
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... |