#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
string s;
vector<vector<char>> grid(n + 1, vector<char>(m + 1));
vector<vector<ll>> ingots(n + 1, vector<ll>(m + 1, 0)), orbs(n + 1, vector<ll>(m + 1, 0));
for (int i = 0; i < n; i++) {
cin >> s;
for (int j = 0; j < m; j++) {
grid[i][j] = s[j];
}
}
ll wyn = 0;
for (int j = m - 1; j >= 0; j--) {
for (int i = n - 1; i >= 0; i--) {
orbs[i][j] = orbs[i][j + 1] + (grid[i][j] == 'O');
ingots[i][j] = ingots[i + 1][j] + (grid[i][j] == 'I');
wyn += (orbs[i][j] * ingots[i][j]) * (grid[i][j] == 'J');
}
}
cout << wyn << 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... |