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;
#define ll long long
void init() {
}
void solve() {
int h, w;
cin >> h >> w;
string a[h];
for (int i = 0; i < h; i++) cin >> a[i];
int psi[h][w], pso[h][w];
for (int i = 0; i < w; i++) {
psi[h - 1][i] = 0;
for (int j = h - 2; j >= 0; j--) {
psi[j][i] = psi[j + 1][i] + (a[j + 1][i] == 'I');
}
}
for (int i = 0; i < h; i++) {
pso[i][w - 1] = 0;
for (int j = w - 2; j >= 0; j--) {
pso[i][j] = pso[i][j + 1] + (a[i][j + 1] == 'O');
}
}
ll int ans = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (a[i][j] == 'J') {
ans += psi[i][j] * pso[i][j];
}
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
init();
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |