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>
using namespace std;
const int N = 3e3 + 5;
int dp_orb [N][N];
int dp_ingot [N][N];
char g [N][N];
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int r, c;
cin >> r >> c;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> g[i][j];
}
}
for (int i = 0; i < r; i++) {
for (int j = c - 1; j >= 0; j--) {
dp_orb[i][j] = (g[i][j] == 'O');
if (j < c - 1) dp_orb[i][j] += dp_orb[i][j + 1];
}
}
for (int i = 0; i < c; i++) {
for (int j = r - 1; j >= 0; j--) {
dp_ingot[i][j] = (g[j][i] == 'I');
if (j < r - 1) dp_ingot[i][j] += dp_ingot[i][j + 1];
}
}
long long res = 0;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (g[i][j] != 'J') continue;
int tot_orb = (j + 1 < c ? dp_orb[i][j + 1] : 0);
int tot_ingot = (i + 1 < r ? dp_ingot[j][i + 1] : 0);
res += tot_orb * tot_ingot;
}
}
cout << res << '\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... |