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 <iostream>
#include <vector>
using namespace std;
#define int long long
signed main() {
int h, w; cin >> h >> w;
vector<string> grid(h);
for (int i = 0; i < h; ++i) {
cin >> grid[i];
}
vector<vector<int>> row_o(h, vector<int>(w)), col_i(w, vector<int>(h));
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (grid[i][j] == 'O') row_o[i][j]++;
if (grid[i][j] == 'I') col_i[j][i]++;
}
}
for (int i = 0; i < h; ++i) {
for (int j = w-2; j >= 0; --j) {
row_o[i][j] += row_o[i][j+1];
}
}
for (int j = 0; j < w; ++j) {
for (int i = h-2; i >= 0; --i){
col_i[j][i] += col_i[j][i+1];
}
}
int ans = 0;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (grid[i][j] == 'J') ans += row_o[i][j] * col_i[j][i];
}
}
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... |