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 int long long
signed main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
for (int i = 0; i < h; ++i)
cin >> s[i];
vector<vector<int>> cnt_o(h, vector<int>(w, 0));
vector<vector<int>> cnt_i(h, vector<int>(w, 0));
for (int i = h - 1; i >= 0; --i) {
for (int j = 0; j < w; ++j) {
cnt_i[i][j] = ((i + 1 < h) ? cnt_i[i + 1][j] : 0) + (s[i][j] == 'I');
}
}
for (int i = 0; i < h; ++i) {
for (int j = w - 1; j >= 0; --j) {
cnt_o[i][j] = ((j + 1 < w) ? cnt_o[i][j + 1] : 0) + (s[i][j] == 'O');
}
}
int ans = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
ans += (s[i][j] == 'J') * cnt_i[i][j] * cnt_o[i][j];
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |