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;
int main() {
int h, w;
cin >> h >> w;
string arr[h];
for (int i=0; i<h; i++) cin >> arr[i];
long long iron[h+1][w+1], orbs[h+1][w+1];
for (int i=0; i<h+1; i++) iron[i][0] = 0, orbs[i][0] = 0;
for (int i=0; i<w+1; i++) iron[0][i] = 0, orbs[0][i] = 0;
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
if (arr[i][j] == 'I') iron[i+1][j+1] = iron[i][j+1] + 1;
else iron[i+1][j+1] = iron[i][j+1];
if (arr[i][j] == 'O') orbs[i+1][j+1] = orbs[i+1][j] + 1;
else orbs[i+1][j+1] = orbs[i+1][j];
}
}
long long score = 0;
long long ik, jk;
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
if (arr[i][j] == 'J') {
// cout << "POS: " << i << ' ' << j << endl;
ik = i + 1;
jk = j + 1;
long long ot = iron[h][jk] - iron[ik][jk];
long long at = orbs[ik][w] - orbs[ik][jk];
score += (ot * at);
}
}
}
cout << score << 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... |